;Best Assembled with FASM
;Do not use MASM
org 0x0500
use16

cli
	xor	ax, ax
	mov	ds, ax
	mov	es, ax
	mov fs, ax
    mov gs, ax
	mov	ax, 0x9000
	mov	ss, ax
	mov	sp, 0xFFFF
sti

mov word [SECTORS_PER_TRACK],ax
mov word [NUMBER_OF_DRIVES],bx
mov word [NUMBER_OF_HEADS],cx
mov [DRIVE_TYPE],dh
mov [drive],dl
mov word [currentdir],0x0013

push ds
lgdt [gdtinfo]
mov eax,cr0
or al,1
mov cr0,eax

jmp $+2
mov bx,0x08
mov ds,bx
and al,0xFE
mov cr0,eax
pop ds

mov ax,0x0003
int 10h

mov ah,33
int 0x33
mov ah,1
int 0x33

;mov bx,0x0f01
;mov eax,0x0b8000
;mov [ds:eax],bx

call clear_screen
call newline
mov di,found
call reg_int

mov si,autorunstr
call pipespace2enter
mov si,autorunstr
call pipestore

kernel:

cmp byte [kernelreturnflag],0xf0
je kerneldone

call newline
mov si,prompt
call prnstr

command_line:
call chkkey
jz command_line
cmp ah,0x48
je previous_comm
cmp ah,0x0f
je page_change_key
cmp ah,0x3b
je help_key
cmp ah,0x3c
je setting_key
jmp command_start

help_key:
call getkey
call newline
mov byte [found],'h'
mov byte [found+1],0
call command
jmp kernel

kerneldone:
mov byte [kernelreturnflag],0x0f
jmp word [kernelreturnaddr]

setting_key:
call getkey
call newline
jmp c_setting_f

previous_comm:
mov si,found
call prnstr
mov di,si
jmp command_set

page_change_key:
jmp page_change

command_start:
mov di,found
command_set:
call getarg

cmp byte [found],0
;cmp al,0
je kernel

call newline

mov si,found
mov di,c_load
call cmpstr
jc load_link

mov si,found
mov di,c_save
call cmpstr
jc save_link

mov si,found
mov di,c_batch
call cmpstr
jc batch_link

mov si,found
mov di,c_text
call cmpstr
jc text_link

mov si,found
mov di,c_code
call cmpstr
jc text_link

mov si,found
mov di,c_print
call cmpstr
jc text_link

mov si,found
mov di,c_video
call cmpstr
jc video_link

mov si,found
mov di,c_vedit
call cmpstr
jc vedit_link

mov si,found
mov di,c_frame
call cmpstr
jc c_frame_f_link

mov si,found
mov di,c_clock
call cmpstr
jc clock_link

jmp extracomms

load_link:
jmp load_f

save_link:
jmp save_f

batch_link:
jmp batch

text_link:
jmp text

video_link:
jmp video

vedit_link:
jmp vedit

c_frame_f_link:
jmp c_frame_f

clock_link:
jmp clock

extracomms:

mov si,found
mov di,c_run
call cmpstr
jc run_link

mov si,found
mov di,c_drive
call cmpstr
jc c_drive_f_link

mov si,found
mov di,c_drive2
call cmpstr
jc c_drive2_f_link

mov si,found
mov di,c_loc
call cmpstr
jc c_loc_f_link

mov si,found
mov di,c_loc2
call cmpstr
jc c_loc2_f_link

mov si,found
mov di,c_loc3
call cmpstr
jc c_loc3_f_link

mov si,found
mov di,c_setdir
call cmpstr
jc c_setdir_f_link

mov si,found
mov di,c_dir
call cmpstr
jc c_dir_f

mov si,found
mov di,c_htod
call cmpstr
jc c_htod_f_link

mov si,found
mov di,c_bhtod
call cmpstr
jc c_bhtod_f_link

jmp extracomm2

run_link:
jmp run

c_drive_f_link:
jmp c_drive_f

c_drive2_f_link:
jmp c_drive2_f

c_loc_f_link:
jmp c_loc_f

c_loc2_f_link:
jmp c_loc2_f

c_loc3_f_link:
jmp c_loc3_f

c_setdir_f_link:
jmp c_setdir_f

c_dir_f:
mov byte [found],'q'
jmp fdir

c_htod_f_link:
jmp c_htod_f

c_bhtod_f_link:
jmp c_bhtod_f

extracomm2:

mov si,found
mov di,c_reset
call cmpstr
jc c_reset_f_link

mov si,found
mov di,c_cls
call cmpstr
jc c_cls_f_link

mov si,found
mov di,c_prompt
call cmpstr
jc c_prompt_f_link

mov si,found
mov di,c_color
call cmpstr
jc c_color_f_link

mov si,found
mov di,c_color2
call cmpstr
jc c_color2_f_link

mov si,found
mov di,c_typemode
call cmpstr
jc c_typemode_f_link

mov si,found
mov di,c_videomode
call cmpstr
jc c_videomode_f_link

jmp extracomm3

c_reset_f_link:
jmp c_reset_f

c_cls_f_link:
jmp c_cls_f

c_prompt_f_link:
jmp c_prompt_f

c_color_f_link:
jmp c_color_f

c_color2_f_link:
jmp c_color2_f

c_typemode_f_link:
jmp c_typemode_f

c_videomode_f_link:
jmp c_videomode_f

extracomm3:

mov si,found
mov di,c_memsize
call cmpstr
jc c_memsize_f_link

mov si,found
mov di,c_reboot
call cmpstr
jc c_reboot_f_link

mov si,found
mov di,c_restart
call cmpstr
jc c_restart_f_link

mov si,found
mov di,c_page
call cmpstr
jc c_page_f_link

mov si,found
mov di,c_star
call cmpstr
jc c_mousemode_f_link

mov si,found
mov di,c_sound
call cmpstr
jc c_sound_f_link

mov si,found
mov di,c_cli
call cmpstr
jc c_cli_f_link

mov si,found
mov di,c_hlt
call cmpstr
jc c_hlt_f_link

mov si,found
mov di,c_fhlt
call cmpstr
jc c_fhlt_f_link

mov si,found
mov di,c_jmp
call cmpstr
jc c_jmp_f_link

mov si,found
mov di,c_paint
call cmpstr
jc c_paint_f_link

mov si,found
mov di,c_score
call cmpstr
jc c_score_f_link

mov si,found
mov di,c_play
call cmpstr
jc c_play_f_link

mov si,found
mov di,c_calc
call cmpstr
jc c_calc_f_link

mov si,found
mov di,c_bcalc
call cmpstr
jc c_bcalc_f_link

jmp extracomms4

c_memsize_f_link:
jmp c_memsize_f

c_reboot_f_link:
jmp c_reboot_f

c_restart_f_link:
jmp c_restart_f

c_page_f_link:
jmp c_page_f

c_mousemode_f_link:
jmp c_mousemode_f

c_sound_f_link:
jmp c_sound_f

c_cli_f_link:
jmp c_cli_f

c_hlt_f_link:
jmp c_hlt_f

c_fhlt_f_link:
jmp c_fhlt_f

c_jmp_f_link:
jmp c_jmp_f

c_paint_f_link:
jmp c_paint_f

c_score_f_link:
jmp c_score_f

c_play_f_link:
jmp c_play_f

c_calc_f_link:
jmp c_calc_f

c_bcalc_f_link:
jmp c_bcalc_f

extracomms4:

mov si,found
mov di,c_size
call cmpstr
jc c_size_f_link

mov si,found
mov di,c_scrollmode
call cmpstr
jc c_scrollmode_f_link

mov si,found
mov di,c_slowmode
call cmpstr
jc c_slowmode_f_link

mov si,found
mov di,c_debug
call cmpstr
jc debug_link

mov si,found
mov di,c_driveinfo
call cmpstr
jc c_driveinfo_f_link

mov si,found
mov di,c_settime
call cmpstr
jc c_settime_f_link

mov si,found
mov di,c_setdate
call cmpstr
jc c_setdate_f_link

mov si,found
mov di,c_install
call cmpstr
jc c_install_f_link

mov si,found
mov di,c_head
call cmpstr
jc c_head_f_link

mov si,found
mov di,c_track
call cmpstr
jc c_track_f_link

mov si,found
mov di,c_point
call cmpstr
jc c_point_f_link

mov si,found
mov di,c_icon
call cmpstr
jc c_icon_f_link

mov si,found
mov di,c_length
call cmpstr
jc c_length_f_link

mov si,found
mov di,c_rollcolor
call cmpstr
jc c_rollcolor_f_link

mov si,found
mov di,c_scrolllen
call cmpstr
jc c_scrolllen_f_link

jmp extracomm5

c_size_f_link:
jmp c_size_f

c_scrollmode_f_link:
jmp c_scrollmode_f

c_slowmode_f_link:
jmp c_slowmode_f

debug_link:
jmp debug

c_driveinfo_f_link:
jmp c_driveinfo_f

c_settime_f_link:
jmp c_settime_f

c_setdate_f_link:
jmp c_setdate_f

c_install_f_link:
jmp c_install_f

c_head_f_link:
jmp c_head_f

c_track_f_link:
jmp c_track_f

c_point_f_link:
jmp c_point_f

c_icon_f_link:
jmp c_icon_f

c_length_f_link:
jmp c_length_f

c_rollcolor_f_link:
jmp c_rollcolor_f

c_scrolllen_f_link:
jmp c_scrolllen_f

extracomm5:

mov si,found
mov di,c_difficulty
call cmpstr
jc c_difficulty_f_link

mov si,found
mov di,c_doc
call cmpstr
jc c_doc_f_link

mov si,found
mov di,c_read
call cmpstr
jc c_read_f_link

mov si,found
mov di,c_type
call cmpstr
jc c_type_f

mov si,found
mov di,c_fname
call cmpstr
jc fname_link

mov si,found
mov di,c_fnew
call cmpstr
jc filenew_link

mov si,found
mov di,c_fsave
call cmpstr
jc filesave_link

mov si,found
mov di,c_rename
call cmpstr
jc rename_link

mov si,found
mov di,c_del
call cmpstr
jc del_link

mov si,found
mov di,c_roam
call cmpstr
jc roam_link

mov si,found
mov di,c_alarm
call cmpstr
jc alarm_link

mov si,found
mov di,c_alarmtext
call cmpstr
jc alarmtext_link

mov si,found
mov di,c_autostart
call cmpstr
jc autostart_link

mov si,found
mov di,c_setting
call cmpstr
jc setting_link

mov si,found
mov di,c_pipe
call cmpstr
jc pipe_link

mov si,found
mov di,c_micro
call cmpstr
jc c_micro_f_link

mov si,found
mov di,c_multi
call cmpstr
jc c_multi_f_link

mov si,found
mov di,c_cursor
call cmpstr
jc c_cursor_f_link

mov si,found
mov di,c_help
call cmpstr
jc c_help_f

mov si,found
mov di,c_step
call cmpstr
jc step_link

mov si,found
mov di,c_newdir
call cmpstr
jc dirnew_link

call microkernel
;microkernel_kernel_loop:

mov byte bl,[found]
cmp bl,'z'
je fdir_link
cmp bl,'a'
je fdir_link
cmp bl,'q'
je fdir_link

;mov byte bl,[found]
cmp bl,'x'
je filesave_link
;mov byte bl,[found]
cmp bl,'n'
je filenew_link

jmp command_link

c_difficulty_f_link:
jmp c_difficulty_f

c_doc_f_link:
jmp doc

c_read_f_link:
jmp read

c_type_f:
mov si,c_text
call pipespace2enter
mov si,c_text
call pipestore
mov ax,0x1C0D
call keybsto
mov ax,0x0100
call keybsto
jmp kernel

fname_link:
jmp fname

alarm_link:
jmp alarm

alarmtext_link:
jmp alarmtext

setting_link:
jmp c_setting_f

pipe_link:
jmp pipe

autostart_link:
jmp c_autostart_f

c_micro_f_link:
jmp c_micro_f

c_multi_f_link:
jmp c_multi_f

c_cursor_f_link:
jmp c_cursor_f

c_help_f:
mov ax,0x3b00
call keybsto
jmp kernel

step_link:
jmp step

filesave_link:
jmp filesave

filenew_link:
jmp filenew

dirnew_link:
mov byte [found],'d'
jmp filenew

rename_link:
mov byte [found],'r'
jmp filenew

del_link:
mov byte [found],'x'
jmp filenew

fdir_link:
jmp fdir

roam_link:
mov byte [found],'r'
jmp fdir

command_link:
mov al,[found]
mov [var_c],al
call command
mov al,[found]
cmp [var_c],al
jne .done
mov si,imsge
call prnstr
.done:
jmp kernel

load_f:
call getno
mov ah,0x02
jmp drive_comm

save_f:
call getno
mov ah,0x03
jmp drive_comm

run:
mov word bx,[loc]
;sub bx,0x0500
call bx
jmp kernel

batch:
mov word [ymouse],0
batchset:
call chkkey
jz .bufferclear
call getkey
jmp batchset
.bufferclear:
call newline
mov si,[loc]
add word si,[ymouse]
mov di,tempstr
;add di,[ymouse]
cmp byte [si],0x00
je kernel
batchloop:
lodsb
inc word [ymouse]
cmp al,0x00
je .end
cmp al,0x0D
je .end
cmp al,0x0A
je .skip
stosb
;inc word [ymouse]
jmp batchloop
.end:
cmp byte [si],0x0A
jne .skip
inc word [ymouse]
;add word [ymouse],0x0002
.skip:
mov al,0x20
stosb
xor al,al
stosb
;add word [ymouse],2
;mov si,tempstr
;call prnstr
mov si,tempstr
call pipespace2enter
mov si,tempstr
call pipestore

mov byte [kernelreturnflag],0xf0
mov word [kernelreturnaddr],batchset
jmp command_start

microkernel:
cmp byte [micro],0xf0
je .enabled
ret
.enabled:
mov dl,[absoluteSector]
mov [LBUTTON],dl
mov dl,[absoluteHead]
mov [RBUTTON],dl
mov dl,[absoluteTrack]
mov [MBUTTON],dl

mov si,ImageName
mov di,ImageNameTemp
mov cx,0x000B
call memcpy

mov si,found
mov di,ImageName
mov cx,0x0008
call memcpys

mov di,ImageName
add di,0x0008
mov al,'C'
stosb
mov al,'O'
stosb
mov al,'M'
stosb

call checkfname

mov si,found
call strshiftr

mov word [comm],0x0f0f
mov byte [found],'c'
mov bx,microkernel_ret
mov [extra],bx
;mov di,[locf7]
;stc
jmp fdir
microkernel_ret:

mov si,found
call strshift

mov dx,[comm]
cmp dx,0xf0f0
jne .fail

mov si,ImageNameTemp
mov di,ImageName
mov cx,0x000B
call memcpy

;jmp .fail
pop ax
;jmp kernel
jmp run
.fail:

mov di,ImageName
add di,0x0008
mov al,'B'
stosb
mov al,'A'
stosb
mov al,'T'
stosb

mov si,found
call strshiftr

mov word [comm],0x0f0f
mov byte [found],'c'
mov bx,microkernel2_ret
mov [extra],bx
jmp fdir
microkernel2_ret:

mov si,found
call strshift

mov si,ImageNameTemp
mov di,ImageName
mov cx,0x000B
call memcpy

mov dx,[comm]
cmp dx,0xf0f0
jne .fail

pop ax
jmp batch

.fail:
mov dl,[LBUTTON]
mov [absoluteSector],dl
mov dl,[RBUTTON]
mov [absoluteHead],dl
mov dl,[MBUTTON]
mov [absoluteTrack],dl
ret
;jmp microkernel_kernel_loop
;pop ax
;jmp kernel

move_right:
pusha
call getpos
inc dl
call setpos
popa
inc cx
jmp text_control

move_down:
pusha
call getpos
inc dh
call setpos
popa
add cx,80
jmp text_control

text:
mov cx,0x0000
mov si,[loc]
text_loop:
lodsb
inc cx
cmp byte [found],'c'
je code_show
cmp byte [found],'p'
je print_file
call printf
jmp text_loop_check
code_show:
call printh
jmp text_loop_check
print_file:
xor ah,ah
xor dx,dx
int 17h
text_loop_check:
cmp cx,0x200
jge text_shown
jmp text_loop
text_shown:
cmp byte [found],'c'
je code_control
cmp byte [found],'p'
je kernel
text_control:
mov ah,0x00
int 0x16
cmp ah,0x01
je kernel
cmp ah,0x29
je kernel
cmp ah,0x48
je move_up
cmp ah,0x4B
je move_left
cmp ah,0x4D
je move_right
cmp ah,0x50
je move_down
cmp ah,0x3b
je .text_help
cmp ah,0x3d
je .text_copy
cmp ah,0x3f
je .text_spec
cmp ah,0x52
je .text_paste

mov bx,[loc]
add bx,cx
mov [bx],al
call printf
inc cx
jmp text_control
.text_help:
pusha
mov dx,doc_helpstr
xor ah,ah
int 61h
popa
jmp text_control
.text_copy:
mov bx,[loc]
add bx,cx
;inc bx
mov si,bx
jmp text_control
.text_paste:
lodsb
mov bx,[loc]
add bx,cx
mov byte [bx],al
call printf
inc cx
jmp text_control
.text_spec:
pusha
mov ah,0x49
mov bx,c_loc
mov dx,[loc]
add dx,cx
mov cx,0x0005
int 0x61
popa
jmp text_control

move_up:
pusha
call getpos
dec dh
call setpos
popa
sub cx,80
jmp text_control

move_left:
pusha
call getpos
dec dl
call setpos
popa
dec cx
jmp text_control

code_control:
;mov word cx,[player_x]
call chkkey

jz code_control
cmp ah,0x01
je kernel
cmp ah,0x29
je kernel
cmp ah,0x48
je code_move_up
cmp ah,0x4B
je code_move_left
cmp ah,0x4D
je code_move_right
cmp ah,0x50
je code_move_down
cmp ah,0x3b
je .code_help
cmp ah,0x3d
je .code_copy
cmp ah,0x3f
je .code_spec
cmp ah,0x52
je .code_paste

call gethex
mov bx,[loc]
add bx,cx
mov [bx],al
inc cx
jmp code_control

.code_help:
pusha
call getkey
mov dx,doc_helpstr
xor ah,ah
int 61h
popa
jmp code_control
.code_copy:
call getkey
mov bx,[loc]
add bx,cx
mov si,bx
jmp code_control
.code_paste:
call getkey
lodsb
mov bx,[loc]
add bx,cx
mov byte [bx],al
call printh
inc cx
jmp code_control
.code_spec:
pusha
call getkey
mov ah,0x49
mov bx,c_loc
mov dx,[loc]
add dx,cx
mov cx,0x0005
int 0x61
popa
jmp code_control

code_move_up:
call getkey
pusha
call getpos
dec dh
call setpos
popa
sub cx,40
jmp code_control

code_move_left:
call getkey
pusha
call getpos
sub dl,2
call setpos
popa
dec cx
jmp code_control

code_move_right:
call getkey
pusha
call getpos
add dl,2
call setpos
popa
inc cx
jmp code_control

code_move_down:
call getkey
pusha
call getpos
inc dh
call setpos
popa
add cx,40
jmp code_control

c_drive_f:
mov si,drive
call change
jmp kernel

c_drive2_f:
mov si,drive2
call change
jmp kernel

c_loc_f:
mov al,'F'
call printf
call colon
mov di,comm
call change
call newline
cmp byte [comm],0
je .locf0
cmp byte [comm],1
je .locf1
cmp byte [comm],2
je .locf2
cmp byte [comm],3
je .locf3
cmp byte [comm],4
je .locf4
cmp byte [comm],5
je .locf5
cmp byte [comm],6
je .locf6
cmp byte [comm],7
je .locf7
.locf0:
mov bx,loc
jmp .get
.locf1:
mov bx,locf1
jmp .get
.locf2:
mov bx,locf2
jmp .get
.locf3:
mov bx,locf3
jmp .get
.locf4:
mov bx,locf4
jmp .get
.locf5:
mov bx,locf5
jmp .get
.locf6:
mov bx,locf6
jmp .get
.locf7:
mov bx,locf7
jmp .get
.get:
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
jmp kernel

c_loc2_f:
mov bx,loc2
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
jmp kernel

c_loc3_f:
mov bx,loc3
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
jmp kernel

c_setdir_f:
mov bx,currentdir
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
jmp kernel

c_reset_f:
cli
	xor	ax, ax
	mov	ds, ax
	mov	es, ax
	mov	ax, 0x9000
	mov	ss, ax
	mov	sp, 0xFFFF
sti
push ds
lgdt [gdtinfo]
mov eax,cr0
or al,1
mov cr0,eax

jmp $+2
mov bx,0x08
mov ds,bx
and al,0xFE
mov cr0,eax
pop ds

call reg_int
mov word [currentdir],0x0013
mov ah,0x00
mov al,[mode]
int 0x10
jmp kernel

c_reset_c:
mov ah,0x00
mov al,[mode]
int 10h
ret

c_cls_f:
call clear_screen
xor dx,dx
call setpos
jmp kernel

c_prompt_f:
mov di,prompt
call getstr
jmp kernel

c_color_f:
mov si,color
call change
jmp kernel

c_color2_f:
mov si,color2
call change
jmp kernel

color_switch:
mov dx,[color]
xchg dh,dl
mov [color],dx
ret

c_typemode_f:
not byte [teletype]
jmp kernel

c_videomode_f:
mov si,mode
call change
xor ah,ah
int 10h
jmp kernel

c_memsize_f:
xor ax,ax
int 12h
call printn
call space
mov ah,0x88
int 15h
call printn
call newline
mov si,freespacestr
call prnstr
call colon
call space
call calculate_fat
mov word bx,[loc3]
call ReadSectors
call calculate_free_space
mov ax,[var_b]
call printwordh
mov al,'/'
call printf
;mov ax,9216
mov ax,[bpbTotalSectors]
call printwordh
call space
mov ax,[var_b]
mov bx,100
xor dx,dx
mul bx
;mov bx,9216
mov bx,[bpbTotalSectors]
div bx
call printn
mov al,'%'
call printf
;call newline
;mov eax,0xe820
;int 15h
;call printn
;call newline
;mov eax,0xe801
;int 15h
;call printn
jmp kernel

printf_c:
pusha
mov bh,[page]
mov ah,0x09
mov bl,[color]
mov cx,0x0001
int 0x10
popa
ret

printf_b:
pusha
call printf_c
call getpos
inc dl
call setpos_c
popa
ret

printf:

cmp byte [teletype],0xf0
je printt

pusha
mov bh,[page]
mov ah,0x09
mov bl,[color]
mov cx,0x0001
int 0x10
call update_pos
popa
ret

printt:
pusha
mov ah,0x0e
mov bh,[color2]
mov bl,[page]
int 10h
popa
ret

readchar:
mov ah,0x08
int 10h
ret

getpos:
mov ah,0x03
mov bh,[page]
int 10h
ret

setpos_c:
mov ah,0x02
mov bh,[page]
int 10h
ret

setpos:
cmp dl,0
jl update_pos_c_z
cmp dh,0
jl update_pos_r_z
cmp dh,24
jg update_pos_r
cmp dl,79
jg update_pos_c
jmp update_pos_e
update_pos_r_z:
xor dh,dh
jmp setpos
update_pos_c_z:
add dl,80
dec dh
jmp setpos
update_pos_c:
inc dh
sub dl,80
jmp setpos
update_pos_r:
cmp byte [scrollmode],0x0f
je update_scroll_off
call scroll_down
mov dh,25
sub dh,[scrolllength]
jmp setpos
update_scroll_off:
call clear_screen
xor dh,dh
jmp setpos
update_pos_e:
mov ah,0x02
mov bh,[page]

int 10h
ret

clearline:
mov al,0x20
mov cx,0x4f
.loop:
call printf
dec cx
cmp cx,0
jge .loop
call color_switch
call printf_c
call color_switch
call getpos
sub dl,0x50
call setpos
ret

clear_screen:
pusha
mov ax,0x0600
call clear_bios_function
popa
ret

clear_bios_function:
mov ch,0x00
mov cl,0x00
mov dl,79
mov dh,24
mov bh,[color]
cmp byte [teletype],0xf0
jne .clear_screen_tele
mov bh,[color2]
.clear_screen_tele:
cmp byte [rollcolor],0xf0
jne .clear_screen_rolloff
rol bh,4
.clear_screen_rolloff:
int 10h
ret

clean_screen:
mov ax,0x0600
mov ch,0x00
mov cl,0x00
mov dl,79
mov dh,24
mov bh,0x00
int 10h
ret

scroll_down:
pusha
mov ah,0x06
mov al,[scrolllength]
call clear_bios_function
popa
ret

update_pos:
call getpos
inc dl
call setpos
ret

printn_big:
mov edx,eax
xor eax,eax
push ax
.loop:
mov eax,edx
xor edx,edx
mov ecx,10
div ecx
xchg eax,edx
add eax,0x30
push ax
cmp edx,0
jg .loop
.printloop:
pop ax
cmp ax,0
je .done
call printf
jmp .printloop
.done:
ret

printn:
mov dx,ax
xor ax,ax
push ax
.loop:
mov ax,dx
xor dx,dx
mov cx,10
div cx
xchg ax,dx
add ax,0x30
push ax
cmp dx,0
jg .loop
.printloop:
pop ax
cmp ax,0
je .done
call printf
jmp .printloop
.done:
ret

printnb:
mov bl,'A'
push bx
mov bh,al
.reverse:
mov al,bh
mov bl,10
mov ah,0
div bl
mov bh,al
mov al,ah
add al,48
push ax
cmp bh,0
jg .reverse
.printne:
pop ax
cmp al,'A'
jne .printnf
jmp .printnq
.printnf:
call printf
jmp .printne
.printnq:
ret

printh:
mov [comm],al
shr al,4
cmp al,10
sbb al,69h
das
call printf
mov al,[comm]
ror al,4
shr al,4
cmp al,10
sbb al,69h
das
call printf
ret

printwordh:
push ax
mov al,ah
call printh
pop ax
call printh
ret

printdwordh:
push ax
mov ax,dx
call printwordh
pop ax
call printwordh
ret

printdwordh_full:
ror eax,16
call printwordh
ror eax,16
call printwordh
ret

gethex:
call getkey
call printf
call atohex
shl al,4
mov [comm],al

call getkey
call printf
call atohex
mov ah,[comm]
add al,ah
ret

atohex:
cmp al,0x3a
jle hex_num_found
cmp al,0x5a
jg hex_small_found
add al,0x20
hex_small_found:
sbb al,0x28
hex_num_found:
sbb al,0x2f
ret

prnstr:
lodsb
or al,al
jz .prnend
call printf
jmp prnstr
.prnend:
ret

prnstr_dos:
lodsb
cmp al,'$'
je .prnend
cmp al,0x0D
je .enter
cmp al,0x0A
je .enter
call printf
jmp prnstr_dos
.prnend:
ret
.enter:
inc si
call newline
jmp prnstr_dos

chkkey:
mov ah,0x11
;mov ah,0x01
int 0x16
ret

getkey:
call chkkey
jz getkey
;cmp ah,0x0F
;je .skip
;cmp ah,0x44
;je .skip
cmp ah,0x0F
je .pagekey
cmp ah,0x44
je .quitkey
jmp .done
.pagekey:
call page_change_c
ret
.quitkey:
call directgetkey
pop ax
jmp kernel
.done:
mov ah,0x10
;xor ah,ah
int 0x16
;.skip:
ret

directgetkey:
call chkkey
jz directgetkey
mov ah,0x10
;xor ah,ah
int 0x16
ret

getkeyflag:
mov ah,0x12
int 16h
ret

getno:
push bx
push cx
push dx
xor bx,bx
.getno_loop:
call getkey
call printf
cmp al,0x0D
je .getno2e
sub al,0x30
mov cl,al
mov ax,bx
mov dx,0x000a
mul dx
mov bx,ax
xor ch,ch
add bx,cx
jmp .getno_loop
.getno2e:
mov ax,bx
pop dx
pop cx
pop bx
ret

getno_big:
push bx
push cx
push dx
xor ebx,ebx
.getno_loop:
call getkey
call printf
cmp al,0x0D
je .getno2e
sub al,0x30
mov cl,al
mov eax,ebx
mov ebx,0xa
mul ebx
mov ebx,eax
mov al,cl
xor ecx,ecx
mov cl,al
add ebx,ecx
jmp .getno_loop
.getno2e:
mov eax,ebx
pop dx
pop cx
pop bx
ret

getstr:
call getkey
call printf
cmp al,0x0d
je .strf
cmp ah,0x01
je .strf
cmp ah,0x0e
je .strb
stosb
jmp getstr
.strb:
dec di
cmp byte [teletype],0xf0
je getstr
call eraseback
call eraseback
jmp getstr
.strf:
mov ax,0x0000
stosb
ret

getstr_dos:
call getkey
call printf
dec cx
inc byte [bx]
cmp al,0x0d
je .strf
cmp ah,0x01
je .strf
cmp ah,0x0e
je .strb
cmp cx,0
je .strf
stosb
jmp getstr_dos
.strb:
dec di
cmp byte [teletype],0xf0
je getstr_dos
call eraseback
call eraseback
jmp getstr_dos
.strf:
mov al,'$'
stosb
ret

getarg:
call getkey
call printf
cmp al,0x20
je .argf
cmp al,0x0d
je .argf
cmp ah,0x01
je .arge
cmp ah,0x0e
je .argb
stosb
jmp getarg
.argb:
dec di
cmp byte [teletype],0xf0
je getarg
call eraseback
call eraseback
jmp getarg
.argf:
mov ax,0x0000
stosb
ret
.arge:
mov byte [found],0x00
ret

eraseback:
call getpos
dec dl
call setpos
mov al,0x20
call printf_c
ret

storeline:
pusha
mov cx,0x0050
mov di,tempstr
.loop:
push cx
call readchar
xchg ah,al
stosw
call update_pos
pop cx
dec cx
cmp cx,0
jg .loop
popa
ret

restoreline:
pusha
mov cx,0x0050
mov si,tempstr
;sub si,0x0500
.loop:
lodsw
mov [color],al
mov al,ah
call printf
dec cx
cmp cx,0
jg .loop
popa
ret

storescreen:
pusha
xor dx,dx
call setpos
mov cx,0x07CF
mov di,[loc3]
.loop:
push cx
call readchar
stosw
call update_pos
pop cx
dec cx
cmp cx,0
jg .loop
popa
ret

restorescreen:
pusha
xor bh,bh
mov bl,[color]
mov di,bx
xor dx,dx
call setpos
mov cx,0x07CF
mov si,[loc3]
;sub si,0x0500
.loop:
lodsw
mov [color],ah
call printf
dec cx
cmp cx,0
jg .loop
mov bx,di
mov [color],bl
popa
ret

cmpstr:
mov al,[si]
mov bl,[di]
cmp al,bl
jne .nequal
;cmp al,dh
;je .cmpend
cmp al,0
je .cmpend
inc di
inc si
jmp cmpstr
.nequal:
clc
ret
.cmpend:
stc
ret

cmpstr_s:
mov al,[si]
mov bl,[di]
dec cx
cmp cx,0
je .cmpend
;cmp al,0x20
;je .cmpend
cmp al,bl
jne .nequal
;cmp al,dh
;je .cmpend
cmp al,0
je .cmpend
inc di
inc si
jmp cmpstr_s
.nequal:
clc
ret
.cmpend:
stc
ret

newline:
pusha
call getpos
xor dl,dl
inc dh
call setpos
popa
ret

drive_comm:
pusha
mov cl,al
mov bx,ds
mov es,bx
mov byte al,[size]
mov ch,[track]
mov dh,[head]
mov byte dl,[drive]
mov word bx,[loc]
stc
int 13h
jnc .success
mov si,imsge
call prnstr
.success:
popa
jmp kernel

timer:
;mov ah,0x00
xor ah,ah
int 0x1a
mov al,ch
call printnb
call colon
mov al,cl
call printnb
call colon
mov al,dh
call printnb
call colon
mov al,dl
call printnb
ret

date:
mov ah,0x04
int 0x1a
mov al,dl
call printh
call colon
mov al,dh
call printh
call colon
mov al,ch
call printh
;call colon
mov al,cl
call printh
ret

command:

mov bx,found
mov al,'d'
cmp [bx],al
je c_date_f_link
mov al,'t'
cmp [bx],al
je c_time_f
mov al,'c'
cmp [bx],al
je c_timer_f_link
mov al,'i'
cmp [bx],al
je c_char_f_link
mov al,'h'
cmp [bx],al
je c_help_mint_link
mov al,'v'
cmp [bx],al
je c_ver_f
;mov al,'i'
;cmp [bx],al
;je c_install_f_link
mov al,'m'
cmp [bx],al
je c_mousemode_c_link
mov al,'s'
cmp [bx],al
je c_space_f_link
mov al,'p'
cmp [bx],al
je c_pause_f_link
mov al,'u'
cmp [bx],al
je c_up_f_link
mov al,'b'
cmp [bx],al
je c_below_f_link
mov al,'o'
cmp [bx],al
je c_oh_f_link
mov al,'l'
cmp [bx],al
je c_line_f_link
mov al,'e'
cmp [bx],al
je c_exit_f
ret

c_date_f_link:
jmp c_date_f

c_timer_f_link:
jmp c_timer_f

c_char_f_link:
jmp c_char_f

c_pause_f_link:
jmp c_pause_f

c_up_f_link:
jmp c_up_f

c_below_f_link:
jmp c_below_f

c_oh_f_link:
jmp c_oh_f

c_line_f_link:
jmp c_line_f

c_space_f_link:
jmp c_space_f

c_help_mint_link:
jmp c_help_mint

;c_install_f_link:
;jmp c_install_f

c_mousemode_c_link:
jmp c_mousemode_f

c_ver_f:
mov si,verstring
call prnstr
mov si,found
call strshift
jmp command

c_time_f:
call printf
call colon
call time
mov si,found
call strshift
jmp command

c_date_f:
call printf
call colon
call date
mov si,found
call strshift
jmp command

c_timer_f:
call printf
call colon
call timer
mov si,found
call strshift
jmp command

c_char_f:
mov si,found
call strshift
mov al,[found]
call printf
mov si,found
call strshift
jmp command

c_exit_f:
call printf
xor bx,bx
mov cx,0x0102
mov ax,0x530e
int 0x15
mov cx,0x0003
mov bx,0x0001
mov ax,0x5307
int 0x15

xor bx,bx
mov ax,0x5301
int 0x15
xor bx,bx
mov cx,0x0102
mov ax,0x530e
int 0x15
mov cx,0x0003
mov bx,0x0001
mov ax,0x5307
int 0x15
mov si,found
call strshift
jmp command

c_pause_f:
call getkey
mov si,found
call strshift
jmp command

c_up_f:
mov ax,0x0608
call clear_bios_function
call getpos
sub dh,8
call setpos
mov si,found
call strshift
jmp command

c_below_f:
mov ax,0x0702
call clear_bios_function
mov si,found
call strshift
jmp command

c_oh_f:
call getpos
sub dh,8
call setpos
mov si,found
call strshift
jmp command

c_line_f:
call newline
mov si,found
call strshift
jmp command

c_space_f:
call space
mov si,found
call strshift
jmp command

c_help_mint:
mov si,main_list
call prnstr
call newline
mov si,editor_list
call prnstr
call newline
mov si,setting_list
call prnstr
call newline
mov si,setting2_list
call prnstr
call newline
mov si,showsetting_list
call prnstr
call newline
mov si,setting_switch_list
call prnstr
call newline
mov si,redo_list
call prnstr
call newline
mov si,assembly_code
call prnstr
call newline
mov si,common_control
call prnstr
call newline
mov si,loc_command
call prnstr
call newline
mov si,experimental
call prnstr
call newline
mov si,file_command
call prnstr
call newline
mov si,dir_command
call prnstr
call newline
mov si,interrupt_api
call prnstr
call newline
mov si,interrupt2_api
call prnstr
call newline
mov si,time_list
call prnstr
call newline
mov si,extra_list
call prnstr
call newline
mov si,mint_list
call prnstr
call newline
mov si,mint2_list
call prnstr
mov si,found
call strshift
jmp command

c_install_f:

mov ax,ds
mov es,ax

mov ax,0x0246
mov bx,[loc]
mov cx,0x0001
mov dh,0x00
mov byte dl,[drive]
int 0x13
jnc c_install_hwri
jmp c_installend_f
c_install_hwri:
mov si,imsgh
call prnstr
c_install_wri:
xor ax,ax
mov es,ax
mov cx,0x0001
mov dh,00h
mov byte dl,[drive2]
mov bx,[loc]
mov ax,0x0346
int 13h
jc c_installend_f
;xor ax,ax
;mov es,ax
;mov cx,0x0002
;mov dh,00h
;mov byte dl,[drive2]
;mov bx,1000h
;mov ax,0x030d
;int 13h
;jc c_installend_f
mov si,imsgs
call prnstr
jmp c_installsuccess_f
c_installend_f:
mov si,imsge
call prnstr
c_installsuccess_f:
;mov si,found
;call strshift
;jmp command
jmp kernel

time:
mov ah,0x02
int 0x1a
mov al,ch
call printh
call colon
mov al,cl
call printh
call colon
mov al,dh
call printh
ret

c_cli_f:
cli
jmp kernel

c_hlt_f:
hlt
jmp kernel

c_fhlt_f:
mov si,shutdownstr
call prnstr
.loop:
cli
hlt
jmp .loop

c_jmp_f:
mov word bx,[loc]
;sub bx,0x0500
jmp bx
;jmp kernel

c_reboot_f:
mov byte dl,[drive]
int 0x19
mov word [472h],1234h
jmp 0FFFFh:0
jmp kernel

c_restart_f:
in al,0x64
cmp al,0x02
je c_restart_f
mov al,0xfe
out 0x64,al
jmp kernel

c_page_f:
mov si,page
call change
mov byte al,[page]
mov ah,0x05
int 10h
jmp kernel

c_sound_f:
mov ax,0x0e07
int 0x10

; ;Beep:     PROC USES AX BX CX
    ; IN AL, 61h  ;Save state
    ; PUSH AX 
    ; MOV BX, 6818; 1193180/175
    ; MOV AL, 6Bh  ; Select Channel 2, write LSB/BSB mode 3
    ; OUT 43h, AL 
    ; MOV AX, BX 
    ; ;OUT 24h, AL  ; Send the LSB
	; OUT 42h, AL  ; Send the LSB
    ; MOV AL, AH
    ; OUT 42h, AL  ; Send the MSB
    ; IN AL, 61h   ; Get the 8255 Port Contence
    ; OR AL, 3h
    ; OUT 61h, AL  ;End able speaker and use clock channel 2 for input
    ; MOV CX, 03h ; High order wait value
    ; MOV DX, 0D04h; Low order wait value
    ; MOV AX, 86h;Wait service
    ; INT 15h
    ; POP AX;restore Speaker state
    ; OUT 61h, AL
    ; ;RET
; jmp kernel

;call ProgramPIT
in al,0x61
mov ah,al
or al,3
cmp ah,al
je .done
out 0x61,al
.done:
;jmp kernel
;call PlayWAV
mov ax,0x80
mov al,[size]
int 0x1a
mov cx,0xffff
sound_loop:
dec cx
mov al,0x1
out 0x61,al
cmp cx,0x0000
je sound_loop
jmp kernel

c_mousemode_f:
mov ax,0x0013
int 10h
JMP MAINP

PS2SET:
  mov  al, 0xa8
  out  0x64, al
  call CHKPRT
ret


CHKPRT:
  xor  cx, cx		
 .again:
  in   al, 0x64
  test al, 2
  jz  .chkprtgo
  jmp .again
.chkprtgo:
ret


WMOUS:
  mov  al, 0xd4
  out  0x64, al
  call CHKPRT
ret


MBUFFUL:
  xor  cx, cx
 .mn:
  in   al, 0x64
  test al, 0x20
  jz  .mnn
  loop .mn
 .mnn:
ret



ACTMOUS:
  call WMOUS
  mov  al, 0xf4
  out  0x60, al
  call CHKPRT
  call CHKMOUS
ret

CHKMOUS:
  mov  bl, 0
  xor  cx, cx
 .vrd:
  in   al, 0x64	
  test al, 1
  jnz .yy
  loop .vrd
  mov  bl, 1
 .yy:
ret


DKEYB:
  mov  al, 0xad
  out  0x64, al
  call CHKPRT
ret


EKEYB:
  mov  al, 0xae
  out  0x64, al
  call CHKPRT
ret

GETB:
 .cagain:
  call CHKMOUS
or bl,bl
jz GETB_exit
cmp byte [found],'s'
je mouse_action_star
jmp .cagain
GETB_exit:
  call DKEYB
  xor  ax, ax
  in   al, 0x60
  mov  dl, al
  call EKEYB
  mov  al, dl
ret
mouse_action_star:
call mousedrawstar
jmp GETB

GETFIRST:
  call GETB
  xor  ah, ah
  mov  bl, al
  and  bl, 1
  mov  BYTE [LBUTTON], bl
  mov  bl, al
  and  bl, 2
  shr  bl, 1
  mov  BYTE [RBUTTON], bl
  mov  bl, al
  and  bl, 4
  shr  bl, 2
  mov  BYTE [MBUTTON], bl
  mov  bl, al
  and  bl, 16
  shr  bl, 4
  mov  BYTE [XCOORDN], bl
  mov  bl, al
  and  bl, 32
  shr  bl, 5
  mov  BYTE [YCOORDN], bl
  mov  bl, al
  and  bl, 64
  shr  bl, 6
  mov  BYTE [XFLOW], bl
  mov  bl, al
  and  bl, 128
  shr  bl, 7
  mov  BYTE [YFLOW], bl
ret



GETSECOND:
  call GETB
  xor  ah, ah
  mov  BYTE [XCOORD], al
ret


GETTHIRD:
  call GETB
  xor  ah, ah
  mov  BYTE [YCOORD], al
ret

MAINP:
  call PS2SET
  call ACTMOUS
  call GETB	
mouse_main:
  call GETFIRST
  call GETSECOND
  call GETTHIRD

 mov BYTE [row], 10
 mov BYTE [col], 0

cmp byte [found],'s'
je no_disp_select
jmp mouse_disp
no_disp_select:
jmp no_mouse_disp
mouse_disp:
 call GOTOXY
call newline
mov si,prompt
call prnstr
mov al,'X'
call printf
mov byte al,[xmouse]
call printnb
call space
mov al,'Y'
call printf
mov byte al,[ymouse]
call printnb
call newline
 mov  si, strcdx
 call prnstr
 mov  al, BYTE [XCOORDN]
 or   al, al
 jz  .negative
 mov  si, strneg
 call prnstr
 jmp .positive
.negative:
 call space
.positive:
 xor  ah, ah
 mov  al, BYTE [XCOORD]
 call DISPDEC
 call newline

 mov  si, strcdy	; display the text for Ycoord
 call prnstr
 mov  al, BYTE [YCOORDN]
 or   al, al
 jz  .negativex
 mov  si, strneg	; if the sign bit is 1 then display - sign
 call prnstr
 jmp .positivex
.negativex:
 call space
.positivex:
 xor  ah, ah
 mov  al, BYTE [YCOORD]
 call DISPDEC
 call newline


 mov  si, strlbt	; display the text for Lbutton
 call prnstr
 mov  al, BYTE [LBUTTON]
 xor  ah, ah
 call DISPDEC
  call newline


 mov  si, strrbt	; display the text for Rbutton
 call prnstr
 mov  al, BYTE [RBUTTON]
 xor  ah, ah
 call DISPDEC
 call newline
 

 mov  si, strmbt	; display the text for Mbutton
 call prnstr
 mov  al, BYTE [MBUTTON]
 xor  ah, ah
 call DISPDEC
 call newline
no_mouse_disp:
call update_mouse

    xor  ax, ax
    mov  ah, 0x11
    int  0x16
    jnz quitprog

jmp mouse_main

quitprog:
mov si,found
call strshift
call c_reset_c
jmp command

update_mouse:

mov byte al,[XCOORD]
mov word bx,[xmouse]

cmp al,0x7f
jg update_x_pos
add bx,ax
jmp update_x_pos_done
update_x_pos:
sub bx,ax
update_x_pos_done:
mov word [xmouse],bx

mov byte al,[YCOORD]
mov word bx,[ymouse]

cmp al,0x7f
jg update_y_pos
sub bx,ax
jmp update_y_pos_done
update_y_pos:
add bx,ax
update_y_pos_done:
mov word [ymouse],bx
xor bx,bx
mov word [XCOORD],bx
mov word [YCOORD],bx
mov word [XCOORDN],bx
mov word [YCOORDN],bx
ret
mousedrawstar:
mov bh,[page]
mov word cx,[xmouse]
mov word dx,[ymouse]
mov al,cl
mov ah,0x0c
int 10h
ret

DISPDEC:
    mov  BYTE [var_x], 0x00
    mov  WORD [var_b], ax
    xor  ax, ax
    xor  cx, cx
    xor  dx, dx
    mov  bx, 10000
    mov  WORD [var_a], bx
   .mainl:
    mov  bx, WORD [var_a]
    mov  ax, WORD [var_b]
    xor  dx, dx
    xor  cx, cx
    div  bx
    mov  WORD [var_b], dx
    jmp .ydisp
   
   .vdisp:
    cmp  BYTE [var_x], 0x00
    je .nodisp

   .ydisp:
    mov  ah, 0x0E			    
    add  al, 48 			     
    mov  bx, 1 
    int  0x10				    
    mov  BYTE [var_x], 0x01
   jmp .yydis

   .nodisp:

   .yydis:
    xor  dx, dx
    xor  cx, cx
    xor  bx, bx
    mov  ax, WORD [var_a]
    cmp  ax, 1
    je .bver
    cmp  ax, 0
    je .bver
    mov  bx, 10
    div  bx
    mov  WORD [var_a], ax
   jmp .mainl

   .bver:
   ret

GOTOXY:
    mov dl, BYTE [col]
    mov dh, BYTE [row]
call setpos
ret

c_rollcolor_f:
not byte [rollcolor]
jmp kernel

c_scrollmode_f:
not byte [scrollmode]
jmp kernel

c_slowmode_f:
not byte [slowmode]
jmp kernel

c_size_f:
mov si,size
call change
jmp kernel

debug_int:
pusha

mov si,dis
call prnstr
call colon
pop ax
call printwordh
call space

mov si,sis
call prnstr
call colon
pop ax
call printwordh
call space

mov si,bps
call prnstr
call colon
pop ax
call printwordh
call space

mov si,sps
call prnstr
call colon
pop ax
call printwordh
call space

mov si,bxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,dxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,cxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,axs
call prnstr
call colon
pop ax
mov [player_x],ax
mov [player_y],bx
call printwordh
call newline

mov si,ips
call prnstr
call colon
pop bx
pop ax
push ax
push bx
call printwordh
call space

mov si,flags
call prnstr
call colon
pushf
pop ax
call printwordh
call space

mov si,dss
call prnstr
call colon
mov ax,ds
call printwordh
call space

mov si,ess
call prnstr
call colon
mov ax,es
call printwordh
call space

mov si,sss
call prnstr
call colon
mov ax,ss
call printwordh
call space

mov si,css
call prnstr
call colon
mov ax,cs
call printwordh
;call space
mov ax,[player_x]
mov bx,[player_y]
ret

debug:
pusha

mov si,dis
call prnstr
call colon
pop ax
call printwordh
call space

mov si,sis
call prnstr
call colon
pop ax
call printwordh
call space

mov si,bps
call prnstr
call colon
pop ax
call printwordh
call space

mov si,sps
call prnstr
call colon
pop ax
call printwordh
call space

mov si,bxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,dxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,cxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,axs
call prnstr
call colon
pop ax
mov [player_x],ax
call printwordh
call newline

mov si,ips
call prnstr
call colon
call .ip
.ip:
pop ax
call printwordh
call space

mov si,flags
call prnstr
call colon
pushf
pop ax
call printwordh
call space

mov si,dss
call prnstr
call colon
mov ax,ds
call printwordh
call space

mov si,ess
call prnstr
call colon
mov ax,es
call printwordh
call space

mov si,sss
call prnstr
call colon
mov ax,ss
call printwordh
call space

mov si,css
call prnstr
call colon
mov ax,cs
call printwordh
;call space
mov ax,[player_x]
jmp kernel

c_driveinfo_f:
push es
mov dl,[drive]
xor ax,ax
mov es,ax
mov di,ax
mov ah, 8
int 13h                       ; get drive parameters
mov [DRIVE_TYPE], bl
and cx, 3Fh                   ; maximum sector number
mov [SECTORS_PER_TRACK], cx
mov [NUMBER_OF_DRIVES], dl
movzx dx, dh                  ; maximum head number
add dx, 1
mov [NUMBER_OF_HEADS], dx
pop es

mov si,drive_f
call prnstr
mov al,[drive]
cmp al,0x00
je di_imsgf
cmp al,0x80
je di_imsgh
mov si,imsgo
call prnstr
jmp di_imsg_e
di_imsgf:
mov si,imsgf
call prnstr
jmp di_imsg_e
di_imsgh:
mov si,imsgh
call prnstr
;jmp di_imsg_e
di_imsg_e:
mov al,[drive]
call printh
call colon
mov al,[drive]
call printnb
call newline

mov si,drive_type_string
call prnstr
mov al,[DRIVE_TYPE]
call printh
call newline
mov si,drive_number_string
call prnstr
mov al,[NUMBER_OF_DRIVES]
call printh
call newline
mov si,drive_spt_string
call prnstr
mov al,[SECTORS_PER_TRACK]
call printwordh
call newline
mov si,drive_head_string
call prnstr
mov al,[NUMBER_OF_HEADS]
call printwordh

jmp kernel

change:
call getno
mov [si],al
ret

drawdot:
mov ah,0x0c
int 10h
ret

c_paint_f:
mov ax,0x0013
int 10h

mov si,[loc]
mov cx,0x0000
mov dx,0x0000
image_loop:
lodsb
push ax
mov al,ah
call drawdot
pop ax
call drawdot
inc cx
cmp cx,320
jne image_loop
mov cx,0x0000
inc dx
cmp dx,200
jne image_loop
mov word [player_x],20
mov word [player_y],20
mov word [player2_x],20
mov word [player2_y],20
mov word [comm],0x1914
mov word [var_b],0x1914
paint_draw:
mov ch,0x00
mov dh,0x00
mov cl,[player_x]
mov dl,[player_y]
mov bh,[page]
mov al,[color]
call drawdot
mov cl,[player2_x]
mov dl,[player2_y]
mov bh,[page]
mov al,[color2]
call drawdot

call getkey
paint_control:
cmp ah,0x4b
je paint_key_left
cmp ah,0x4d
je paint_key_right
cmp ah,0x48
je paint_key_up
cmp ah,0x50
je paint_key_down
jmp paint2_control

paint_key_left:
mov cx,[player_x]
mov dx,[player_y]
dec cx
dec word [comm]
jmp paint_key_done
paint_key_right:
mov cx,[player_x]
mov dx,[player_y]
inc cx
inc word [comm]
jmp paint_key_done
paint_key_up:
mov cx,[player_x]
mov dx,[player_y]
dec dx
sub word [comm],0x0140
jmp paint_key_done
paint_key_down:
mov cx,[player_x]
mov dx,[player_y]
inc dx
add word [comm],0x0140
jmp paint_key_done

paint_key_done:
mov [player_x],cx
mov [player_y],dx
mov bx,[loc]
add bx,[comm]
mov al,[color]
mov byte [bx],al
jmp paint_draw

paint2_control:
cmp ah,0x11
je paint_key_w
cmp ah,0x1e
je paint_key_a
cmp ah,0x1f
je paint_key_s
cmp ah,0x20
je paint_key_d
jmp other_key

paint_key_a:
mov cx,[player2_x]
mov dx,[player2_y]
dec cx
dec word [var_b]
jmp paint2_key_done
paint_key_d:
mov cx,[player2_x]
mov dx,[player2_y]
inc cx
inc word [var_b]
jmp paint2_key_done
paint_key_w:
mov cx,[player2_x]
mov dx,[player2_y]
dec dx
sub word [var_b],0x0140
jmp paint2_key_done
paint_key_s:
mov cx,[player2_x]
mov dx,[player2_y]
inc dx
add word [var_b],0x0140
jmp paint2_key_done

paint2_key_done:
mov [player2_x],cx
mov [player2_y],dx
mov bx,[loc]
add bx,[var_b]
mov al,[color2]
mov byte [bx],al
jmp paint_draw

other_key:
cmp ah,0x3d
je paint_copy
cmp ah,0x52
je paint_paste
cmp ah,0x01
je paint_exit
cmp ah,0x29
je paint_exit
mov byte [color],ah
mov byte [color2],al
jmp paint_draw

paint_copy:
mov bx,[loc]
add bx,[comm]
mov si,bx
jmp paint_draw

paint_paste:
mov bx,[loc]
add bx,[comm]
lodsb
mov [bx],al
mov [color],al
inc word [comm]
inc word [player_x]
jmp paint_draw

paint_exit:
jmp kernel

c_play_f:
mov byte [player_y],0x0c
mov byte [player_x],0x00
mov byte [player2_y],0x0c
mov byte [player2_x],0x4f
mov byte [ball_y],0x0c
mov byte [ball_x],0x0c
mov byte [down_flag],0xf0
mov byte [right_flag],0xf0
mov byte [AI_flag],0xf0
mov word [var_a],0x0000
mov word [extra],0x0000
mov byte al,[color]
mov byte [color2],al
call clean_screen
xor dx,dx
call setpos
play_loop:
call play2_draw
call play_draw
cmp byte [score],0xf0
jne score_off
call score_draw
score_off:
call ball_draw
xor dx,dx
call setpos_c
cmp byte [slowmode],0xf0
je play_slowmode_on
call delay
jmp play_delay_done
play_slowmode_on:
call slow
play_delay_done:
mov byte [color],0x00
call ball_draw
call play2_draw
call play_draw
mov byte al,[color2]
mov byte [color],al
call ball_update
call setpos_c
cmp byte [AI_flag],0xF0
je AI_play_loop
jmp AI_player_chance
AI_play_loop:
mov byte al,[play_chance_flag]

cmp byte al,[difficulty]
jle AI_on
;jg AI_player_chance

AI_player_chance:
xor al,al
mov byte [play_chance_flag],al
xor dx,dx
call setpos
call chkkey
jz play_loop

call getkey
cmp ah,0x01
je kernel
cmp ah,0x29
je kernel
cmp ah,0x12
je play_clear
cmp ah,0x48
je player1_up
cmp ah,0x50
je player1_down
cmp ah,0x3b
je play_help
;cmp ah,0x0f
;je switch_AI
cmp ah,0x3C
je switch_AI
cmp ah,0x3D
je switch_AI

cmp byte [AI_flag],0xF0
je AI_on

cmp ah,0x11
je player2_up
cmp ah,0x1f
je player2_down
call getkeyflag
and ax,0x0040
or ax,0x0040
je switch_AI
jmp play_loop

AI_on:
jmp AI_play

switch_AI:
not byte [AI_flag]
jmp play_loop

player1_up:
mov dh,[player_y]
dec dh
mov [player_y],dh
jmp play_loop
player1_down:
mov dh,[player_y]
inc dh
mov [player_y],dh
jmp  play_loop
player2_up:
mov dh,[player2_y]
dec dh
mov [player2_y],dh
jmp play_loop
player2_down:
mov dh,[player2_y]
inc dh
mov [player2_y],dh
jmp  play_loop
play_clear:
call clean_screen
xor dx,dx
call setpos
jmp play_loop
play_help:
mov dx,play_helpstr
xor ah,ah
int 61h
;mov al,'e'
;mov ah,0x12
;call keybsto
jmp play_loop

AI_play:
inc al
mov byte [play_chance_flag],al
mov dh,[player2_y]
inc dh
cmp byte [ball_y],dh
jg AI_ball_ahead
jl AI_ball_behind
jmp AI_exit
AI_ball_ahead:
inc dh
jmp AI_exit
AI_ball_behind:
dec dh
jmp AI_exit

AI_exit:
dec dh
mov byte [player2_y],dh
jmp play_loop

play_draw:
mov cl,[length]
mov dl,[player_x]
mov dh,[player_y]
play_draw_loop:
call setpos_c
mov al,0xdb
call printf_c
dec cl
inc dh
cmp dh,0x19
jg play_loop_extra
cmp dh,0x01
jl play_loop_less
cmp cl,0x00
jg play_draw_loop
jmp play_loop_exit
play_loop_extra:
mov dh,0x19
sub dh,[length]
mov [player_y],dh
jmp play_loop
play_loop_less:
mov dh,0x00
mov [player_y],dh
jmp play_loop
play_loop_exit:
ret

play2_draw:
mov cl,[length]
mov dl,[player2_x]
mov dh,[player2_y]
play2_draw_loop:
call setpos_c
mov al,0xdb
call printf_c
dec cl
inc dh
cmp dh,0x19
jg play2_loop_extra
cmp dh,0x01
jl play2_loop_less
cmp cl,0x00
jg play2_draw_loop
jmp play2_loop_exit
play2_loop_extra:
mov dh,0x19
sub dh,[length]
mov [player2_y],dh
jmp play_loop
play2_loop_less:
mov dh,0x00
mov [player2_y],dh
jmp play_loop
play2_loop_exit:
ret

ball_draw:
mov dl,[ball_x]
mov dh,[ball_y]
inc dl
call setpos_c
mov al,0xdb
call printf_b
call printf_b
mov dl,[ball_x]
mov dh,[ball_y]
inc dh
call setpos_c
mov al,0xdb
call printf_b
call printf_b
call printf_b
call printf_b

mov dl,[ball_x]
mov dh,[ball_y]
add dh,2
call setpos_c
mov al,0xdb
call printf_b
call printf_b
call printf_b
call printf_b

mov dl,[ball_x]
mov dh,[ball_y]
add dh,3
inc dl
call setpos_c
mov al,0xdb
call printf_b
call printf_b
ret

ball_update:
mov dl,[ball_x]
mov dh,[ball_y]

cmp byte [down_flag],0xf0
jne ball_going_up
inc dh
jmp vertical_update_done
ball_going_up:
dec dh
vertical_update_done:

cmp byte [right_flag],0xf0
jne ball_going_left
inc dl
jmp horizontal_update_done
ball_going_left:
dec dl
horizontal_update_done:

cmp dl,0x4b
jg right_wall
cmp dl,0x01
jl left_wall
cmp dh,0x15
jg bottom_wall
cmp dh,0x01
jl top_wall

jmp bounds_done
left_wall:
mov byte ah,[player_y]
call play_check_collision
jnc left_wall_fine
inc word [extra]
left_wall_fine:
not byte [right_flag]
jmp bounds_done
right_wall:
mov byte ah,[player2_y]
call play_check_collision
jnc right_wall_fine
inc word [var_a]
right_wall_fine:
not byte [right_flag]
jmp bounds_done
bottom_wall:
mov dh,0x15
not byte [down_flag]
jmp bounds_done
top_wall:
mov dh,0x00
not byte [down_flag]
;jmp bounds_done
bounds_done:
mov byte [ball_x],dl
mov byte [ball_y],dh
ret

score_draw:
mov dx,0x1722
call setpos
mov word ax,[var_a]
call printwordh
call colon
mov word ax,[extra]
call printwordh
ret

play_check_collision:
mov byte [XFLOW],dh
add dh,3
cmp dh,ah
jge coll_end_fine
jmp coll_detected
coll_end_fine:
sub dh,2
add byte ah,[length]
cmp dh,ah
jle coll_start_fine
jmp coll_detected
coll_start_fine:
mov byte dh,[XFLOW]
clc
ret
coll_detected:
mov byte dh,[XFLOW]
stc
ret

c_calc_f:
mov al,0x31
call printf
call colon
call getno
push ax
call newline
mov al,0x32
call printf
call colon
call getno
push ax
call newline
mov si,calc_options
call prnstr
call newline
call getno
mov dx,ax
push dx
call newline
pop dx
pop cx
pop ax
cmp dl,1
je calc_add
cmp dl,2
je calc_sub
cmp dl,3
je calc_mul
cmp dl,4
je calc_div
cmp dl,5
je calc_dtoh
calc_add:
add ax,cx
jmp calc_exit
calc_sub:
sub ax,cx
jmp calc_exit
calc_mul:
xor dx,dx
mul cx
cmp dx,0
je .skipmul
push ax
mov ax,dx
call printn
call colon
pop ax
.skipmul:
jmp calc_exit
calc_div:
xor dx,dx
div cx
push dx
push ax
mov al,'Q'
call printf
call colon
pop ax
call printn
call space
mov al,'R'
call printf
call colon
pop ax
call printn
jmp kernel
calc_dtoh:
push cx
call printwordh
call colon
pop ax
call printwordh
jmp kernel
calc_exit:
call printn
jmp kernel

c_bcalc_f:
mov al,0x31
call printf
call colon
call getno_big
mov [player_x],eax
call newline
mov al,0x32
call printf
call colon
call getno_big
mov [player2_x],eax
call newline
mov si,calc_options
call prnstr
call newline
call getno
mov dx,ax
push dx
call newline
pop dx
mov eax,[player_x]
mov ecx,[player2_x]
cmp dl,1
je .calc_add
cmp dl,2
je .calc_sub
cmp dl,3
je .calc_mul
cmp dl,4
je .calc_div
cmp dl,5
je .calc_dtoh
.calc_add:
add eax,ecx
jmp .calc_exit
.calc_sub:
sub eax,ecx
jmp .calc_exit
.calc_mul:
xor edx,edx
mul ecx
cmp edx,0
je .skipmul
mov [player_x],eax
mov eax,edx
call printn_big
call colon
mov eax,[player_x]
.skipmul:
jmp .calc_exit
.calc_div:
xor edx,edx
div ecx
mov [player_x],eax
mov [player2_x],edx
mov al,'Q'
call printf
call colon
mov eax,[player_x]
call printn_big
call space
mov al,'R'
call printf
call colon
mov eax,[player2_x]
call printn_big
jmp kernel
.calc_dtoh:
mov [player_x],ecx
call printdwordh_full
call colon
mov eax,[player2_x]
call printdwordh_full
jmp kernel
.calc_exit:
call printn_big
jmp kernel

delay:
xor ah,ah
int 1ah
mov byte [comm],dl
delay_loop:
xor ah,ah
int 1ah
cmp byte [comm],dl
je delay_loop
ret

slow:
mov ah,0x02
int 1ah
mov al,dh
mov byte [comm],al
slow_loop:
mov ah,0x02
int 0x1a
cmp byte dh,[comm]
je slow_loop
ret

colon:
mov al,':'
call printf
ret

comma:
mov al,','
call printf
ret

space:
mov al,' '
call printf
ret

c_head_f:
mov si,head
call change
jmp kernel

c_track_f:
mov si,track
call change
jmp kernel

strshift:
inc si
mov al,[si]
dec si
mov [si],al
inc si
cmp al,0
jne strshift
ret

strshiftr:
call strlen
mov di,si
dec si
call memcpyr
ret

strlen:
xor cx,cx
.loop:
lodsb
inc cx
cmp al,0
jne .loop
ret

c_point_f:
mov ax,0x0013
int 10h
mov word [comm],0
mov si,[loc]
point_loop:
lodsb
mov byte [player_x],al
lodsb
mov byte [player_y],al
inc word [comm]
xor ch,ch
xor dh,dh
mov cx,[player_x]
mov dx,[player_y]
mov byte al,[color]
call drawdot
cmp word [comm],512
jl point_loop
jmp kernel

c_icon_f:
mov ax,0x0013
int 10h
mov si,[loc]
mov cx,100
mov dx,50
icon_loop:
lodsb
call drawdot
inc cx
cmp cx,132
jl icon_loop
mov cx,100
inc dx
cmp dx,66
jl icon_loop
jmp kernel

c_settime_f:
mov al,'H'
call printf
call colon
mov si,player_x
call change
call newline
mov al,'M'
call printf
call colon
mov si,player_y
call change
call newline
mov al,'S'
call printf
call colon
mov si,player2_x
call change

mov byte ch,[player_x]
mov byte cl,[player_y]
mov byte dh,[player2_x]
xor dl,dl
mov ah,0x03
int 0x1a
jmp kernel

c_setdate_f:
mov al,'C'
call printf
call colon
mov si,player_x
call change
call newline
mov al,'Y'
call printf
call colon
mov si,player_y
call change
call newline
mov al,'M'
call printf
call colon
mov si,player2_x
call change
call newline
mov al,'D'
call printf
call colon
mov si,player2_y
call change

mov byte ch,[player_x]
mov byte cl,[player_y]
mov byte dh,[player2_x]
mov byte dl,[player2_y]
mov ah,0x05
int 0x1a
jmp kernel

; LBA = (cluster - 2) * sectors per cluster

ClusterLBA:
          sub     ax, 0x0002                          ; zero base cluster number
          xor     cx, cx
          mov     cl, BYTE [bpbSectorsPerCluster]     ; convert byte to word
          mul     cx
          add     ax, WORD [datasector]               ; base data sector
          ret

; absolute sector = (logical sector / sectors per track) + 1
; absolute head   = (logical sector / sectors per track) MOD number of heads
; absolute track  = logical sector / (sectors per track * number of heads)

LBACHS:
          xor     dx, dx                              ; prepare dx:ax for operation
          div     WORD [bpbSectorsPerTrack]           ; calculate
          inc     dl                                  ; adjust for sector 0
          mov     BYTE [absoluteSector], dl
          xor     dx, dx                              ; prepare dx:ax for operation
          div     WORD [bpbHeadsPerCylinder]          ; calculate
          mov     BYTE [absoluteHead], dl
          mov     BYTE [absoluteTrack], al
          ret

ReadSectors:
xor bp,bp
mov es,bp
     Read_Sectors_MAIN:
          mov     di, 0x0005                          ; five retries for error
     Read_Sectors_SECTORLOOP:
          push    ax
          push    bx
          push    cx
          call    LBACHS                              ; convert starting sector to CHS
          mov     ah, 0x02                            ; BIOS read sector
          mov     al,[size]
          mov     ch, BYTE [absoluteTrack]            ; track
          mov     cl, BYTE [absoluteSector]           ; sector
          mov     dh, BYTE [absoluteHead]             ; head
          ;mov     dl, BYTE [bsDriveNumber]            ; drive
mov byte dl,[drive]
          int     0x13                                ; invoke BIOS
          jnc     Read_Sectors_SUCCESS                ; test for read error
		  mov si,imsge
		  call prnstr
		  jmp Read_Sectors_SUCCESS
          xor     ax, ax                              ; BIOS reset disk
          int     0x13                                ; invoke BIOS
          dec     di                                  ; decrement error counter
          pop     cx
          pop     bx
          pop     ax
          jnz     Read_Sectors_SECTORLOOP             ; attempt to read again
          int     0x18
     Read_Sectors_SUCCESS:
	      mov     al, '.'
          call    printf
          pop     cx
          pop     bx
          pop     ax
          add     bx, WORD [bpbBytesPerSector]        ; queue next buffer
          inc     ax                                  ; queue next sector
          loop    Read_Sectors_MAIN                   ; read next sector
          ret
fname:
mov di,ImageName
call getstr
call checkfname
jmp kernel

checkfname:
mov cx,0x000B
mov si,ImageName
.loop:
lodsb

cmp al,0x00
je .zero
cmp al,0x60
jg .small
cmp al,0x2E
je .dot
;dec cx
loop .loop
;cmp cx,0x0000
;jg .loop
ret
.small:
;inc cx
sub al,0x20
dec si
mov [si],al
;inc si
jmp .loop
.zero:
inc cx
dec si
mov di,si
.zeroloop:
mov al,0x20
stosb
dec cx
cmp cx,0
jg .zeroloop
ret
.dot:
mov al,[si]
cmp al,'.'
je .doubledot
;add si,3
;mov [si],0
;sub si,3
dec si
push si
call strshift
pop si
push si
;mov byte [si],0x20
;inc si
mov di,ImageName
add di,0x000A
add si,2

mov al,[si]
mov byte [si],0x20
mov [di],al
dec di
dec si

mov al,[si]
mov byte [si],0x20
mov [di],al
dec di
dec si

mov al,[si]
mov byte [si],0x20
mov [di],al
pop si
mov al,0x20
.dotloop:
cmp si,di
jge .dotdone
mov [si],al
inc si
jmp .dotloop
.dotdone:
jmp checkfname
.doubledot:
dec di
mov si,ImageName
add si,0x000B
mov al,0x20
.doubledotloop:
stosb
cmp di,si
jl .doubledotloop
ret

fdir:
cmp byte [found],'i'
je .fdir_interrupt
cmp byte [found],'t'
je .fdir_interrupt
;cmp byte [found],'c'
;je .fdir_interrupt
jmp fdir_not_interrupt
;mov di,ImageName
;mov bx,di
.fdir_interrupt:
mov ax,[loc]
mov [var_a],ax
mov [loc],di
fdir_not_interrupt:
call LOAD_ROOT
jmp fileload
jmp kernel

calculate_root:
     
          xor     cx, cx
          xor     dx, dx
          mov     ax, 0x0020                           ; 32 byte directory entry
          mul     WORD [bpbRootEntries]                ; total size of directory
          div     WORD [bpbBytesPerSector]             ; sectors used by directory
          xchg    ax, cx
          
mov     al, BYTE [bpbNumberOfFATs]            ; number of FATs
mul     WORD [bpbSectorsPerFAT]               ; sectors used by FATs
add     ax, WORD [bpbReservedSectors]         ; adjust for bootsector
;mov ax,[currentdir]
mov     WORD [datasector], ax                 ; base of root directory
add     WORD [datasector], cx
mov ax,[currentdir]
pusha
cmp byte [found],'i'
je .callnodata
cmp byte [found],'c'
je .callnodata
call newline
mov si,c_dir
call prnstr
call colon
popa
pusha
call printwordh
call space
mov si,c_size
call prnstr
call colon
popa
pusha
mov ax,cx
call printwordh
call space
.callnodata:
call newline
popa
ret

LOAD_ROOT:


     call calculate_root
	 
mov word bx,[loc2]
		  mov dl,[size]
		  push dx
	 
cmp word [currentdir],0x0013
jne .infolder
		  mov [size],cl
          call    ReadSectors
		  pop dx
		  mov [size],dl
ret
.infolder:
mov byte [size],1
;mov     dx, WORD [di + 0x001A]
          ;mov     WORD [cluster], dx          
     call calculate_fat
          mov word bx,[loc3]
          call ReadSectors
		  
		  xor ax,ax
          mov es, ax                              ; destination for image
          mov word bx,[loc2]                          ; destination for image
		  push bx
		  call calculate_root
		  ;call newline
;call ReadSectors
;mov word ax,[currentdir]
sub     ax, WORD [datasector]               ; base data sector
xor dx,dx
         xor cx, cx
          mov cl, BYTE [bpbSectorsPerCluster]     ; convert byte to word
          div cx
		  add ax, 0x0002                          ; zero base cluster number

mov word [cluster],ax
mov word [player_x],ax
;mov word [xmouse],0
;jmp .skip
		  .loop:
          mov     ax, WORD [cluster]                  ; cluster to read
          pop     bx                                  ; buffer to read into
          call    ClusterLBA                          ; convert cluster to LBA
cmp byte [found],'i'
je .callnodata
cmp byte [found],'c'
je .callnodata
pusha
call newline
call space
mov al,'L'
call printf
call colon
popa
pusha
call printwordh
popa
pusha
call LBACHS
call space
mov al,'H'
call printf
mov al,'='
call printf
mov byte al,[absoluteHead]
call printh
call colon
mov al,'T'
call printf
mov al,'='
call printf
mov byte al,[absoluteTrack]
call printh
call colon
mov al,'S'
call printf
mov al,'='
call printf
mov byte al,[absoluteSector]
call printh
popa
.callnodata:
          xor     cx, cx
          mov     cl, BYTE [bpbSectorsPerCluster]     ; sectors to read
          call    ReadSectors
		  ;inc word [xmouse]
          push    bx
          ;call calculate_next_cluster
		  ; compute next cluster

          mov     ax, WORD [cluster]                  ; identify current cluster
		  .skip:
		  ;mov [var_b]
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc3]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
          
     .EVEN_CLUSTER:
     
          and     dx, 0000111111111111b               ; take low twelve bits
         jmp     .DONE
         
     .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
          
     .DONE:
		  mov     WORD [cluster], dx
		  ;cmp word [xmouse],4
		  ;jg .close
		  cmp     dx, 0x0FF0                          ; test for end of file
          jb .loop
;.close:
pop bx
mov word ax,[player_x]
mov word [cluster],ax
pop dx
mov [size],dl
ret
fileload:

          mov     cx, WORD [bpbRootEntries]
          mov word di, [loc2]
     .LOOP:
          ;push    cx
          mov     si, ImageName
		  mov ax,[di]
		  cmp ax,0x0000
		  je FAILURE
          push    di
		  ;push cx
cmp byte [found],'i'
je .intnonameload
cmp byte [found],'c'
je .intnonameload
;call newline
;pop cx
;mov     cx, 0x000B
call show_name
.intnonameload:
mov si,ImageName
mov cx, 0x000B
repe  cmpsb
pop di
je LOAD_FAT
;je DONE
cmp byte [found],'q'
je .intload
cmp byte [found],'i'
je .intload
cmp byte [found],'c'
je .intload
call getkey
cmp al,0x0D
je LOAD_FAT
cmp al,0x20
je LOAD_FAT
cmp ah,0x4b
je .back
cmp ah,0x48
je .back
cmp ah,0x01
je FAILURE
.intload:
          ;pop     cx
          add     di, 0x0020
          cmp cx,0
		  jg .LOOP
		  jmp     FAILURE
.back:
sub di,0x0020
mov ax,0x0702
call clear_bios_function
jmp .LOOP

     LOAD_FAT:
     call newline
          mov     dx, WORD [di + 0x001A]
          mov     WORD [cluster], dx          
     call calculate_fat
          mov word bx,[loc3]
          call ReadSectors
		  
		  xor ax,ax
          mov es, ax                              ; destination for image
          mov word bx,[loc]                          ; destination for image
          push bx

     ;----------------------------------------------------
     ; Load Stage 2
     ;----------------------------------------------------

     LOAD_IMAGE:
     
          mov     ax, WORD [cluster]                  ; cluster to read
          pop     bx                                  ; buffer to read into
          call    ClusterLBA                          ; convert cluster to LBA
          xor     cx, cx
          mov     cl, BYTE [bpbSectorsPerCluster]     ; sectors to read
          call    ReadSectors
          push    bx
          ;call calculate_next_cluster
		  ; compute next cluster
mov word ax,[cluster]
mov word [player_x],ax
     ;.loop:
          mov     ax, WORD [cluster]                  ; identify current cluster
		  ;cmp word [xmouse],0
		  ;je .skip
		  ;mov ax, WORD [xmouse]
		  ;.skip:
		  ;mov [var_b]
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc3]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
          
     .EVEN_CLUSTER:
     
          and     dx, 0000111111111111b               ; take low twelve bits
         jmp     .DONE
         
     .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
          
     .DONE:
     
          cmp byte [found],'a'
		  jne complete_load_off
		  ;mov     WORD [xmouse], dx                  ; store new cluster
		  mov     WORD [cluster], dx
          cmp     dx, 0x0FF0                          ; test for end of file
          jb LOAD_IMAGE
		  complete_load_off:
		  ;mov word [xmouse],0
mov word ax,[player_x]
mov word [cluster],ax

     DONE:
pop bx
mov byte [kernelreturnflag],0x0f
clc
mov word [comm],0xf0f0
cmp byte [found],'c'
je callloaddone
cmp byte [found],'i'
je intloaddone
mov si,successstr
call prnstr
call newline
mov al,'C'
call printf
call colon
mov ax,[cluster]
call printwordh
call space
mov si,c_loc
call prnstr
call colon
mov ax,[datasector]
add ax,[cluster]
sub ax,2
call printwordh
call space
mov al,'H'
call printf
mov al,'='
call printf
mov byte al,[absoluteHead]
call printh
call colon
mov al,'T'
call printf
mov al,'='
call printf
mov byte al,[absoluteTrack]
call printh
call colon
mov al,'S'
call printf
mov al,'='
call printf
mov byte al,[absoluteSector]
call printh

mov byte [comm2],'f'
cmp byte [found],'r'
je .roam_on
cmp byte [found],'t'
je .roamt_on
jmp .dont_roam
.roamt_on:
mov byte [comm2],'t'
jmp .dont_roam
.roam_on:
mov byte [comm2],'r'
.dont_roam:

call space
mov si,c_size
call prnstr
call colon
mov ax,[var_p+2]
call printwordh
mov ax,[var_p]
call printwordh
call colon
mov dx,[var_p+2]
mov ax,[var_p]
mov cx,0x0200
div cx
cmp dx,0
je .perfectsector
inc ax
.perfectsector:
call printn

call space
mov byte [found],'f'
call filetype

mov al,[var_x]
and al,0x10
cmp al,0x10
je .dir
jmp .done
.dir:
mov ax,[datasector]
add ax,[cluster]
sub ax,2
cmp [cluster],0
jne .dir_child
sub ax,0x0C
.dir_child:
mov [currentdir],ax
cmp byte [comm2],'r'
je .dir_roam
cmp byte [comm2],'t'
je .dir_roamt
jmp .done
.dir_roam:
mov byte [found],'r'
jmp fdir
.dir_roamt:
mov byte [found],'t'
jmp fdir_not_interrupt
.done:
cmp byte [comm2],'t'
je .roam_done
jmp kernel
.roam_done:
clc
mov bx,[extra]
mov ax,[loc]
mov dx,[var_a]
mov [loc],dx
jmp bx

FAILURE:
stc
mov word [comm],0x0f0f
cmp byte [found],'i'
je intloaddone
cmp byte [found],'c'
je callloaddone
call newline
mov si, imsge
call prnstr
cmp byte [comm2],'t'
je .roam_done
jmp kernel
.roam_done:
clc
mov bx,[extra]
mov ax,[loc]
mov dx,[var_a]
mov [loc],dx
jmp bx

intloaddone:
call newline
mov ax,[loc]
mov dx,[var_a]
mov [loc],dx
mov word dx,[comm]
iret
callloaddone:
call newline
;mov ax,[loc]
;mov dx,[var_a]
;mov [loc],dx
mov bx,[extra]
;sub bx,0x0500
jmp bx
;jmp microkernel_ret

find_next_free_cluster:
mov ax,2
mov [cluster],ax
.loop:
mov ax,[cluster]
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc3]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
          
     .EVEN_CLUSTER:
     
          and     dx, 0000111111111111b               ; take low twelve bits
;pusha
	 ;mov ax,dx
	 ;call printwordh
	 ;call colon
	 ;popa
	 ;mov dx,[bx]
	 ;or dx,0x0fff
	 cmp dx,0
	 je .sete
	 inc word [cluster]
	 jmp .loop
         ;jmp .DONE
         
     .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
     cmp dx,0
	 je .seto
	 inc word [cluster]
	 jmp .loop
.sete:
mov dx,[bx]
or dx,0x0fff
;mov dx,0xFFFF
mov word [bx],dx
;cmp     dx, 0x0FF0
;jb      LOAD_IMAGE
ret
.seto:
mov dx,[bx]
or dx,0xfff0
mov word [bx],dx
ret

calculate_free_space:
mov ax,2
mov [cluster],ax
xor ax,ax
mov [var_b],ax
.loop:
mov ax,[cluster]
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc3]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
     .EVEN_CLUSTER:
          and     dx, 0000111111111111b               ; take low twelve bits
		  jmp .compare
		  .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
	 .compare:
	 cmp dx,0
	 jne .not_free
	 inc word [var_b]
	 .not_free:
	 inc word [cluster]
	 ;cmp word [cluster],9216
	 mov dx,[bpbTotalSectors]
	 cmp word [cluster],dx
	 jge .done
	 jmp .loop
     .done:
ret

delete_cluster:
mov ax,[cluster]
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc3]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
          
     .EVEN_CLUSTER:
     
          and     dx, 0000111111111111b               ; take low twelve bits

	 jmp .setze

     .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
     jmp .setzo
.setze:
mov [cluster],dx
mov dx,[bx]
and dx,0xf000
mov word [bx],dx

mov dx,[cluster]
cmp dx,0x0000
je .done
cmp dx,0x0ff0
jle delete_cluster
jmp .done
.setzo:
mov [cluster],dx
mov dx,[bx]
and dx,0x000f
mov word [bx],dx

mov dx,[cluster]
cmp dx,0x0000
je .done
cmp dx,0x0ff0
jle delete_cluster
.done:
ret

calculate_fat:
; compute size of FAT and store in "cx"
     
          xor     ax, ax
          mov     al, BYTE [bpbNumberOfFATs]          ; number of FATs
          mul     WORD [bpbSectorsPerFAT]             ; sectors used by FATs
          mov     cx, ax

     ; compute location of FAT and store in "ax"

          mov     ax, WORD [bpbReservedSectors]       ; adjust for bootsector
		  ret

save_c:
pusha
mov dx,ds
;xor dx,dx
mov es,dx
mov byte ah,0x03
mov byte ch,0x00
;mov byte cl,[sector]
;mov byte al,[size]
mov byte dh,0x00
mov byte dl,[drive]
;mov word bx,[loc]
int 0x13
popa
ret

filesave_c:
pusha
mov dx,ds
;xor bx,bx
mov es,dx
mov byte ah,0x03
mov byte al,[size]
mov byte ch,[absoluteTrack]
mov byte cl,[absoluteSector]
mov byte dh,[absoluteHead]
mov byte dl,[drive]
int 0x13
jc .error
jmp .done
.error:
mov si,imsge
call prnstr
.done:
popa
ret

filesave:
pusha
mov bx,ds
;xor bx,bx
mov es,bx
mov byte ah,0x03
mov byte al,[size]
mov byte ch,[absoluteTrack]
mov byte cl,[absoluteSector]
mov byte dh,[absoluteHead]
mov byte dl,[drive]
mov word bx,[loc]
int 0x13
jc .error
jmp .done
.error:
mov si,imsge
call prnstr
.done:
popa
jmp kernel

fileload_c:
mov ah, 0x02
mov al,[size]
mov ch, BYTE [absoluteTrack]
mov cl, BYTE [absoluteSector]
mov dh, BYTE [absoluteHead]
mov byte dl,[drive]
int 0x13
ret

filenew:
mov al,[size]
mov [var_x],al
mov byte [size],0x09

cmp byte [found],'r'
je .dont_allocate
cmp byte [found],'x'
je .dont_allocate
call calculate_fat
;inc ax
;xchg ax,cx
mov word bx,[loc3]
call ReadSectors
call find_next_free_cluster
call calculate_fat
;call printwordh
inc ax
xchg ax,cx
;call colon
;call printwordh
mov word bx,[loc3]
call save_c

.dont_allocate:

call LOAD_ROOT
mov cx, WORD [bpbRootEntries]
mov word di,[loc2]
call newline
jmp .loop
.filenew_exit:
mov si,imsge
call prnstr
mov al,[var_x]
mov [size],al
jmp kernel
.loop:
cmp byte [found],'r'
je .show_name
cmp byte [found],'x'
je .show_name
jmp .jump_name
.show_name:
call show_name
call getkey
cmp ah,0x01
je .filenew_exit
cmp ah,0x1c
je .filenew_found
.jump_name:
mov ax,[di]
cmp ax,0x0000
je .filenew_not_found
add di,0x0020
jmp .loop
.rename_file:
mov si,ImageName
mov cx,0x000b
call memcpy
call calculate_root
inc ax
xchg ax,cx
mov word bx,[loc2]
call save_c

mov al,[var_x]
mov [size],al
jmp kernel
.delete_file:
mov al,0xE5
mov [di],al

add di,0x001A

;lodsw
mov ax,[di]
mov [cluster],ax

call calculate_root
inc ax
xchg ax,cx
mov word bx,[loc2]
call save_c

call calculate_fat
mov word bx,[loc3]
call ReadSectors
call delete_cluster
call calculate_fat
inc ax
xchg ax,cx
mov word bx,[loc3]
call save_c

mov al,[var_x]
mov [size],al
jmp kernel
.filenew_not_found:
cmp byte [found],'r'
je kernel
cmp byte [found],'x'
je kernel
.filenew_found:
cmp byte [found],'r'
je .rename_file
cmp byte [found],'x'
je .delete_file
;sub di,0x0006
mov word ax,[cluster]
;inc word ax
mov word [comm],ax
;mov word [cluster],ax
;add di,0x0006
;push di
mov si,ImageName
mov cx,0x000b
call memcpy
;pop di
cmp byte [found],'d'
je .dir
mov al,0x20
stosb
jmp .done
.dir:
mov al,0x10
stosb
.done:
mov al,0x18
stosb
mov al,0x1a
stosb
mov al,0x9a
stosb
mov al,0x42
stosb
mov al,0x7c
stosb
mov al,0x43
stosb
mov al,0x7c
stosb
mov al,0x43
stosb
mov al,0x00
stosb
stosb
mov al,0xca
stosb
mov al,0x93
stosb
mov al,0x76
stosb
mov al,0x43
stosb

;add di,0x000e
mov bx,comm
mov al,[bx]
stosb
inc bx
mov al,[bx]
stosb
inc di
mov al,0x02
stosb

call calculate_root
inc ax
xchg ax,cx
mov word bx,[loc2]
call save_c

mov al,[var_x]
mov [size],al
jmp kernel

filetype:

mov al,[var_x]
and al,0x0F
cmp al,0x0F
je .label

mov al,[var_x]
and al,0x08
cmp al,0x08
je .drive

mov al,[var_x]
and al,0x10
cmp al,0x10
je .dir

mov si,filestr
call prnstr
cmp byte [found],'f'
je .filecheck
ret
.drive:
mov si,c_drive
call prnstr
call attrib
ret
.label:
mov si,labelstr
call prnstr
call attrib
ret
.dir:
mov si,c_dir
call prnstr
call attrib
ret
.filecheck:
call colon
mov si,tempstr
call prnstr

call attrib
call space
mov si,tempstr
mov di,bmps
call cmpstr
jc .bmp
mov si,tempstr
mov di,txts
call cmpstr
jc .txt
mov si,tempstr
mov di,coms
call cmpstr
jc .com
mov si,tempstr
mov di,vids
call cmpstr
jc .vid
mov si,tempstr
mov di,pics
call cmpstr
jc .pic
mov si,tempstr
mov di,pnts
call cmpstr
jc .pnt
ret
.bmp:
mov si,imagestr
call prnstr
call colon
mov si,c_paint
call prnstr
ret
.txt:
mov si,c_text
call prnstr
call colon
mov si,c_doc
call prnstr
call comma
mov si,c_type
call prnstr
call comma
mov si,c_text
call prnstr
ret
.com:
mov si,coms
call prnstr
call colon
mov si,c_code
call prnstr
call comma
mov si,c_run
call prnstr
ret
.vid:
mov si,c_video
call prnstr
call colon
mov si,c_vedit
call prnstr
call comma
mov si,c_video
call prnstr
ret
.pic:
mov si,imagestr
call prnstr
call colon
mov si,c_vedit
call prnstr
call comma
mov si,c_video
call prnstr
ret
.pnt:
mov si,imagestr
call prnstr
call colon
mov si,c_code
call prnstr
call comma
mov si,c_point
call prnstr
ret

attrib:
cmp byte [found],'f'
jne .done

call newline
mov si,attribstr
call prnstr
call colon
mov byte [XFLOW],0x0f

mov al,[var_x]
cmp al,0
je .normal

mov al,[var_x]
and al,0x01
cmp al,0x01
je .read
.readret:

mov al,[var_x]
and al,0x02
cmp al,0x02
je .hidden
.hiddenret:

mov al,[var_x]
and al,0x04
cmp al,0x04
je .system
.systemret:

mov al,[var_x]
and al,0x20
cmp al,0x20
je .archive
.archiveret:

jmp .done
.normal:
cmp byte [XFLOW],0xf0
jne .commaskipn
call comma
.commaskipn:
mov si,normalstr
call prnstr
mov byte [XFLOW],0xf0
jmp .done

.read:
cmp byte [XFLOW],0xf0
jne .commaskipr
call comma
.commaskipr:
mov si,readonlystr
call prnstr
mov byte [XFLOW],0xf0
jmp .readret

.hidden:
cmp byte [XFLOW],0xf0
jne .commaskiph
call comma
.commaskiph:
mov si,hiddenstr
call prnstr
mov byte [XFLOW],0xf0
jmp .hiddenret

.system:
cmp byte [XFLOW],0xf0
jne .commaskips
call comma
.commaskips:
mov si,systemstr
call prnstr
mov byte [XFLOW],0xf0
jmp .systemret

.archive:
cmp byte [XFLOW],0xf0
jne .commaskipa
call comma
.commaskipa:
mov si,archivestr
call prnstr
mov byte [XFLOW],0xf0
jmp .archiveret

.done:
ret

show_name:
call newline
mov cx,0x0020
mov bx,di
call reload_words
mov si,di
add si,0x0008
mov cx,0x0003
push di
mov di,tempstr
call memcpy
xor al,al
stosb
pop di
push di
push si
mov si,di
add si,0x000B
mov cx,0x0015
mov al,[si]
mov [var_x],al
add si,0x0011
lodsw
mov [var_p],ax
lodsw
mov [var_p+2],ax
pop si
pop di

.hexloop:
lodsb
call printh
dec cx
cmp cx,0
jg .hexloop
;call space
call filetype
ret

vedit:
mov dl,[color]
mov [extra],dl
mov dx,0x0A0A
push dx
;mov si,[loc]
mov word [var_b],0x0654
mov word [player_x],0x0001
.loop:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov si,ax
xor dx,dx
call setpos
;mov cx,0x07D0
call memcpyprint
pop dx
push dx
call setpos
.vedit_control:
call getkey
cmp ah,0x01
je .quit
cmp ah,0x48
je .up
cmp ah,0x4b
je .left
cmp ah,0x4d
je .right
cmp ah,0x50
je .down
cmp ah,0x53
je .color_down
cmp ah,0x4F
je .color_up
cmp ah,0x52
je .char_down
cmp ah,0x47
je .char_up
cmp ah,0x51
je .page_down
cmp ah,0x49
je .page_up
cmp ah,0x49
je .page_up
cmp ah,0x3b
je .help
cmp ah,0x3D
je .copy
cmp ah,0x3E
je .paste
cmp ah,0x3f
je .spec
cmp ah,0x40
je .fill
cmp ah,0x41
je .clear
cmp ah,0x42
je .clean
push ax
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
pop ax
mov [bx],al
inc bx
mov ah,[bx]
mov [color],ah
call printf
add word [var_b],2
jmp .vedit_control
.quit:
pop dx
mov dl,[extra]
mov [color],dl
jmp kernel
.up:
sub word [var_b],0x00A0
call getpos
dec dh
call setpos
jmp .vedit_control
.left:
sub word [var_b],2
call getpos
dec dl
call setpos
jmp .vedit_control
.right:
add word [var_b],2
call getpos
inc dl
call setpos
jmp .vedit_control
.down:
add word [var_b],0x00A0
call getpos
inc dh
call setpos
jmp .vedit_control
.color_up:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov al,[bx]
inc bx
inc byte [bx]
mov ah,[bx]
mov [color],ah
call printf
call getpos
dec dl
call setpos
jmp .vedit_control
.color_down:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov al,[bx]
inc bx
dec byte [bx]
mov ah,[bx]
mov [color],ah
call printf
call getpos
dec dl
call setpos
jmp .vedit_control
.char_up:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
inc byte [bx]
mov al,[bx]
inc bx
mov ah,[bx]
mov [color],ah
call printf
call getpos
dec dl
call setpos
jmp .vedit_control
.char_down:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
dec byte [bx]
mov al,[bx]
inc bx
mov ah,[bx]
mov [color],ah
call printf
call getpos
dec dl
call setpos
jmp .vedit_control
.copy:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov al,[bx]
inc bx
mov ah,[bx]
mov di,ax
jmp .vedit_control
.paste:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov [bx],di
mov si,bx

inc si
lodsb
mov [color],al
sub si,2
lodsb
call printf
inc si

add word [var_b],2
jmp .vedit_control
.spec:
mov word ax,[var_b]
xor dx,dx
mov cx,2
div cx
xor dx,dx
mov cx,80
div cx
push ax
mov bx,strcdx
mov ah,0x45
mov cx,0x0005
int 0x61
pop ax
mov bx,strcdy
mov dx,ax
mov ah,0x45
mov cx,0x0005
int 0x61
jmp .vedit_control
.fill:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov byte [bx],0xdb
mov si,bx
inc si
lodsb
mov [color],al
sub si,2
lodsb
call printf
inc si
add word [var_b],2
jmp .vedit_control
.clear:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov byte [bx],0x20
mov si,bx
inc si
lodsb
mov [color],al
sub si,2
lodsb
call printf
inc si
add word [var_b],2
jmp .vedit_control
.clean:
mov ax,0x0FA0
mov dx,[player_x]
dec dx
mul dx
add ax,[loc]
mov bx,ax
add bx,[var_b]
mov word [bx],0x0f20
mov si,bx
inc si
lodsb
mov [color],al
sub si,2
lodsb
call printf
inc si
add word [var_b],2
jmp .vedit_control
.help:
mov dx,vedit_helpstr
xor ah,ah
int 61h
mov dx,vedit_helpstr2
xor ah,ah
int 61h
mov dx,vedit_helpstr3
xor ah,ah
int 61h
jmp .vedit_control
.page_down:
pop dx
call getpos
push dx
dec word [player_x]
cmp word [player_x],1
jl .frameless
jmp .loop
.frameless:
mov dl,[frame]
mov [player_x],dl
jmp .loop
.page_up:
pop dx
call getpos
push dx
mov dl,[frame]
inc word [player_x]
cmp [player_x],dl
jg .framemore
jmp .loop
.framemore:
mov word [player_x],1
jmp .loop

video:
mov dl,[color]
;push dx
mov [extra],dl
mov si,[loc]
mov word [player_x],0x0001
;mov di,0xB800
;sub di,0x0500
;call memcpy
.loop:
;mov bl,0x36
;mov ax,0x1201
;int 0x10
;call newline
mov dx,0
call setpos
call memcpyprint
;mov bl,0x36
;mov ax,0x1200
;int 0x10
mov dx,[frame]
cmp dx,1
jle .videoexit
cmp byte [slowmode],0xf0
je .slowmode
call delay
jmp .timewarpdone
.slowmode:
call slow
.timewarpdone:
call chkkey
jnz .videoexit
mov dx,[player_x]
cmp dx,[frame]
jge .limit
inc word [player_x]
jmp .loop
.videoexit:
call getkey
mov dl,[extra]
;pop dx
mov [color],dl
jmp kernel
.limit:
mov word [player_x],0x0001
mov si,[loc]
jmp .loop

memcpyprint:
;mov word ax,[player_x]
;xor dx,dx
;mov cx,0x0200
;mul cx
mov bx,0xB800
mov es,bx
xor bx,bx
;mov si,[loc]
;add si,ax
mov cx,0x07D0
.loop:
lodsw
;cmp [es:bx],ax
;je .skip
mov [es:bx],ax
;.skip:
add bx,2
loop .loop
xor bx,bx
mov es,bx
ret

memcpy:
lodsb
stosb
dec cx
cmp cx,0
jg memcpy
ret

memcpys:
lodsb
cmp al,0x00
je .zero
stosb
dec cx
cmp cx,0
jg memcpys
ret
.zero:
mov al,0x20
stosb
dec cx
cmp cx,0
jg .zero
ret

memcpyr:
lodsb
stosb
sub si,2
sub di,2
dec cx
cmp cx,0
jg memcpyr
ret

step:
pushf
mov bp,sp
or word [bp+0],0x0100
popf
jmp run
jmp kernel

reload_words:
cmp cx,0x0000
jle .reload_words_end
dec cx
mov byte al,[bx]
call printf
inc bx
jmp reload_words
.reload_words_end:
ret

doc_up:
call getpos
dec dh
sub word [var_a],0x50
call setpos
jmp doc_shown_control

doc_right:
call getpos
inc dl
inc word [var_a]
call setpos
jmp doc_shown_control

doc:
mov ax,0x0200
xor cx,cx
xor dx,dx
mov byte cl,[size]
mul cx
;cmp dx,0
;jg .small_file
;mov ax,0xFFFF
;.small_file:
mov word [var_b],ax
mov word [var_a],0x0000
mov si,[loc]
doc_loop:
lodsb
inc word [var_a]
call printf
mov word cx,[var_a]
cmp word cx,[var_b]
jge doc_shown_control2
cmp word [var_a],0x07Cf
jge doc_shown
jmp doc_loop
doc_shown:
;mov word [var_a],0x004f
mov word [var_a],0x0050
mov dx,0x0100
call setpos
doc_shown_control2:
dec word [var_a]
doc_shown_control:
call getpos
cmp dh,0x00
jle doc_top_move
cmp dh,0x18
jge doc_bottom_move
jmp doc_control_fine

doc_top_move:
mov byte [player_x],dl
mov byte [player_y],dh
mov dx,0x0000
call setpos
;sub word [var_a],0x0050
mov ax,0x0701
call clear_bios_function
mov word bx,[loc]
add word bx,[var_a]
sub byte bl,[player_x]
sub bx,0x0050
inc bx
mov cx,0x0050
call reload_words
mov byte dl,[player_x]
mov byte dh,[player_y]
inc dh
call setpos
jmp doc_control_fine

doc_bottom_move:
mov byte [player_x],dl
mov byte [player_y],dh
mov dx,0x1800
call setpos
;add word [var_a],0x0050
mov ax,0x0601
call clear_bios_function
mov word bx,[loc]
;add word bx,0x07D0
add word bx,[var_a]
sub byte bl,[player_x]
add bx,0x0050
inc bx
mov cx,0x004f
call reload_words
mov al,[bx]
call printf_c
mov byte dl,[player_x]
mov byte dh,[player_y]
dec dh
call setpos
jmp doc_control_fine

doc_control_fine:

call getkey
cmp ah,0x48
je doc_up
cmp ah,0x4b
je doc_left
cmp ah,0x4d
je doc_right
cmp ah,0x50
je doc_down
cmp ah,0x01
je doc_exit
cmp ah,0x29
je doc_exit
cmp ah,0x3b
je doc_help
cmp ah,0x3d
je doc_copy
cmp ah,0x3f
je doc_spec
cmp ah,0x52
je doc_paste

call printf
inc word [var_a]
mov word bx,[loc]
add word bx,[var_a]
mov byte [bx],al
jmp doc_shown_control
doc_exit:
call newprompt
jmp kernel
doc_help:
mov dx,doc_helpstr
xor ah,ah
int 61h
jmp doc_shown_control
doc_copy:
mov word bx,[loc]
add word bx,[var_a]
inc bx
mov si,bx
jmp doc_shown_control
doc_paste:
inc word [var_a]
mov word bx,[loc]
add word bx,[var_a]
lodsb
mov byte [bx],al
call printf
jmp doc_shown_control
doc_spec:
pusha
mov ah,0x49
mov bx,c_loc
mov dx,[loc]
add dx,[var_a]
inc dx
mov cx,0x0005
int 0x61
popa
jmp doc_shown_control
doc_left:
call getpos
dec dl
dec word [var_a]
call setpos
jmp doc_shown_control

doc_down:
call getpos
inc dh
add word [var_a],0x50
call setpos
jmp doc_shown_control

c_length_f:
mov si,length
call change
jmp kernel

c_htod_f:
call gethex
push ax
call gethex
pop bx
mov ah,bl
push ax
call colon
pop ax
call printn
jmp kernel

c_bhtod_f:
call gethex
push ax
call gethex
pop bx
mov ah,bl
ror eax,16
call gethex
push ax
call gethex
pop bx
mov ah,bl
push ax
call colon
pop ax
call printn_big
jmp kernel

c_scrolllen_f:
mov si,scrolllength
call change
jmp kernel

c_frame_f:
mov si,frame
call change
cmp byte [frame],0
jle .frameless
jmp kernel
.frameless:
mov byte [frame],1
jmp kernel

c_score_f:
not byte [score]
jmp kernel

c_autostart_f:
not byte [autostart]
jmp kernel

c_micro_f:
not byte [micro]
jmp kernel

c_multi_f:
not byte [multi]
jmp kernel

clock:
mov di,found
mov al,'c'
stosb
mov al,'s'
stosb
stosb
mov al,'l'
stosb
mov al,'t'
stosb
mov al,'s'
stosb
mov al,'l'
stosb
mov al,'d'
stosb
mov al,'s'
stosb
call command
call chkkey
jnz kernel
call getpos
sub dh,2
xor dl,dl
call setpos
jmp clock

page_change:
call directgetkey
mov al,[page]
inc al
cmp al,0x07
jle .page_fine
xor al,al
.page_fine:
mov byte [page],al
mov ah,0x05
int 10h
call newprompt
jmp command_line

page_change_c:
call directgetkey
mov al,[page]
inc al
cmp al,0x07
jle .page_fine
xor al,al
.page_fine:
call getpos
push dx
mov byte [page],al
mov ah,0x05
int 10h
pop dx
call setpos
;call newprompt
ret

reg_int:
;call set_timer
;call ProgramPIT
mov ax,0x0001
mov di,int01h
call set_ivt
mov ax,0x0003
mov di,int03h
call set_ivt
mov ax,0x0005
mov di,int05h
call set_ivt
mov ax,0x0006
mov di,int06h
call set_ivt
mov ax,0x0007
mov di,int07h
call set_ivt
mov ax,0x001c
mov di,int1ch
call set_ivt
mov ax,0x001b
mov di,int1bh
call set_ivt
mov ax,0x0020
mov di,int20h
call set_ivt
mov ax,0x0021
mov di,int21h
call set_ivt
mov ax,0x002c
mov di,int2ch
call set_ivt
mov ax,0x004A
mov di,int4ah
call set_ivt
mov ax,0x0060
mov di,int60h
call set_ivt
mov ax,0x0061
mov di,int61h
call set_ivt
mov ax,0x0062
mov di,int62h
call set_ivt
mov ax,0x0064
mov di,int64h
call set_ivt
;mov ax,0x0008
;mov di,int08h
;call set_ivt
;mov ax,0x0009
;mov di,int09h
;call set_ivt
ret

set_ivt:
xor dx,dx
mov es,dx
mov bl,0x04
mul bl
mov bx,ax
xor ax,ax
mov es,ax
mov word [bx],di
add bx,2
mov word [bx],0x0000
ret

ackport:
cmp al,0x0f
jle irqsmall
mov al,0x20
out 0xa0,al
irqsmall:
mov al,0x20
out 0x20,al
ret

clrport64:
;jmp clrport64_loop
in al,0x60
call printf
;clrport64_loop:
in al,0x64
mov ah,al
or al,80h
out 0x61,al
xchg ah,al
out 61h,al

;and al,1
;cmp al,0x01
;jge clrport64
ret

int01h:
cli
pusha
pushf
mov bp,sp
and word [bp+0],0xFEFF
popf
sti
xor dx,dx
mov ds,dx
mov es,dx

call newline

popa
call debug_int
pusha
mov al,0x01
call ackport
call getkey
popa
;pop bx
;pop ax
;xor ax,ax
;push ax
;mov bx,kernel
;push bx
iret

int03h:
pusha
xor ax,ax
mov ds,ax
mov es,ax
call newline
popa
call debug_int
pusha
mov al,0x03
call ackport
popa
iret

int05h:
pusha
xor dx,dx
mov ds,dx
mov es,dx
call storescreen
mov al,0x05
call ackport
popa
iret

int06h:
pusha
xor dx,dx
mov ds,dx
mov es,dx
mov si,invalidstr
call prnstr
call getkey
mov al,0x06
call ackport
popa
iret

int07h:
pusha
xor dx,dx
mov ds,dx
mov es,dx
mov si,nomathprocstr
call prnstr
call getkey
mov al,0x07
call ackport
popa
iret

int1bh:
pusha
xor dx,dx
mov ds,dx
mov es,dx
popa
call debug_int
pusha
call getkey
mov al,0x1b
call ackport
popa
iret

int20h:
xor dx,dx
mov ds,dx
mov es,dx

pop bx
pop ax
xor ax,ax
push ax
mov bx,kernel
push bx

mov al,0x20
call ackport
iret

int21h:
pusha
mov al,0x21
call ackport
xor dx,dx
mov ds,dx
mov es,dx
popa

cmp ah,0x00
je int21h_close_process
cmp ah,0x01
je int21h_read_char
cmp ah,0x02
je int21h_display_char
cmp ah,0x06
je int21h_directinputoutput
cmp ah,0x07
je int21h_read_char_direct
cmp ah,0x08
je int21h_read_char_direct_check
cmp ah,0x09
je int21h_display_string
cmp ah,0x0a
je int21h_get_string
cmp ah,0x25
je int21h_set_interrupt
cmp ah,0x2a
je int21h_get_date
cmp ah,0x2b
je int21h_set_date
cmp ah,0x2c
je int21h_get_time
cmp ah,0x2d
je int21h_set_time
cmp ah,0x30
je int21h_get_dos_ver
cmp ah,0x3B
je int21h_set_dir
cmp ah,0x3D
je int21h_open_file
cmp ah,0x3E
je int21h_save_file
cmp ah,0x40
je int21h_save_file
cmp ah,0x47
je int21h_get_dir
cmp ah,0x4C
je int21h_close_process
cmp ah,0x4D
je int21h_get_return_code
call debug_int
;call clrport64

iret

int21h_read_char:
call getkey
call printf
iret

int21h_display_char:
mov al,dl
call printf
mov al,dl
iret

int21h_directinputoutput:
cmp dl,0xFF
je .input
mov al,dl
call printf
mov al,dl
iret
.input:
xor al,al
call chkkey
jz .zero
iret
.zero:
mov dl,0x0f
iret

int21h_read_char_direct:
call directgetkey
iret

int21h_read_char_direct_check:
call getkey
iret

int21h_display_string:
mov si,dx
push si
mov ah,0x0F
int 0x10
mov bl,bh
xor bh,bh
mov [page],bx

pop si
call prnstr_dos

mov al,0x24
iret

int21h_get_string:
mov bx,dx
mov cx,[bx]
inc bx
mov di,bx
inc di
call getstr_dos
mov al,0x24
iret

int21h_set_interrupt:
xor ah,ah
mov di,dx
call set_ivt
iret

int21h_get_date:
mov al,0x04
int 0x1a
iret

int21h_set_date:
mov al,0x05
int 0x1a
xor al,al
iret

int21h_get_time:
mov al,0x02
int 0x1a
iret

int21h_set_time:
mov al,0x03
int 0x1a
xor al,al
iret

int21h_get_dos_ver:
mov ax,0x0600
iret

int21h_close_process:
mov [returncode],al
push ax
xor al,al
mov ah,0x0F
int 0x10
mov bl,bh
xor bh,bh
mov [page],bx
call newline
mov si,process_returnstr
call prnstr
call colon
pop ax
call printh
pop bx
pop ax
xor ax,ax
push ax
mov bx,kernel
push bx
iret

int21h_get_return_code:
xor ah,ah
mov al,[returncode]
iret

int21h_set_dir:
mov [currentdir],dx
iret

int21h_open_file:

;pop ax
;mov [extra],ax
;inc [var_b]
;pop ax
;pop ax
mov si,dx
mov di,ImageName
mov cx,0x000B
call memcpy
call checkfname
mov di,[locf4]
mov byte [found],'i'

;call clrport64
jmp fdir
iret

int21h_save_file:
mov bx,[locf4]
call filesave_c
clc
iret

int21h_get_dir:
mov dx,[currentdir]
iret

int2ch:
xor ax,ax
mov ds,ax
mov es,ax

mov si,bx
mov di,dx
push cx

call color_switch

call getpos
;push dx
;pop bx
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
call getkey
call colon
mov si,di
call prnstr
call getkey
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
mov al,0x2c
call ackport

iret

int4ah:
;mov cx,0xf000
;.emptyloop:
;cli
;nop
;dec cx
;loop .emptyloop
pusha
mov al,0x4a
call ackport
xor dx,dx
mov ds,dx
mov es,dx

mov ah,0x07
int 0x1a

call newline
mov si,alarmtextstr
call prnstr
call newline

popa
call debug_int
;call clrport64
call getkey
cmp ah,0x1C
je .int4ah_continue
pop ax
;pop ax
;xor ax,ax
;push ax
mov ax,kernel
push ax
iret
.int4ah_continue:
iret

;int08h:
;pusha
;xor dx,dx
;mov ds,dx
;mov es,dx

;mov ax,0x0e43
;int 10h

;mov al,0x08
;call ackport
;call clrport64
;popa
;cmp [EnableDigitized],1                  ;If it's set to 1, process next lines of code
;jne NoDigitizedSound                     ;If not, do the standard irq0 routine
   
;cmp al,0x80                                 ;If the byte taken from the memory is less than 80h,
                                                         ;turn off the speaker to prevent "unwanted" sounds,
;jb TurnOffBeeper                          ;like: ASCII strings (e.g. "WAVEfmt" signature etc).
;mov bx,[WAVSamplingRate]              ;Turn on the speaker with the WAV's sampling rate.
;mov bx,6000
;call Sound_On
;jmp Sound_Done
;TurnOffBeeper:
;call Sound_Off
;Sound_Done:
;inc esi                                         ;Increment ESI to load the next byte
;NoDigitizedSound:   
;iret

;Sound_On:                                     ; A routine to make sounds with BX = frequency in Hz
   ;mov ax,0x34dd                        ; The sound lasts until NoSound is called
   ;mov dx,0x0012                
   ;cmp dx,bx                
   ;jnc Done1               
   ;div bx                
   ;mov bx,ax
   ;in al,0x61
   ;test al,3
   ;jnz A99                
   ;or al,3                                 ;Turn on the speaker itself
   ;out 0x61,al                
   ;mov al,0xb6
   ;out 0x43,al
; A99:    
   ; mov al,bl 
   ; out 0x42,al              
   ; mov al,bh
   ; out 0x42,al
; Done1:
   ; ret

; Sound_Off:
   ; in al,0x61                 
   ; and al,11111100b                               ;Turn off the speaker
   ; out 0x61,al
   ; ret

; PlayWAV:
   ; ;mov [WAVSamplingRate],10000;;;;;;;;;;;Your sampling rate;;;;;;;;;;;;
   ; ;mov [WAVFileSize],;;;;;;;;;;;; Size of your WAV file ;;;;;;;;;;;;;
   ; ;mov esi,FileLoaded ;;;;;;;;;;;;;; ESI = offset where the file is ;;;;;;;;;;;;;
   ; mov esi,0x3000
   ; ;mov cx,[WAVSamplingRate]                    ;IRQ0 fires e.g. 6000 times a second
   ; mov cx,6000
   ; call ProgramPIT                                  ;when a 6000Hz WAV file is played. This is how
                                                              ; ;the speaker can play the digitized sound:
                                                              ; ;it turns on and off very fast with the specified
                                                              ; ;wave sample rate.
   ; ;mov ecx,[WAVFileSize]                         ;Sets the loop point
   ; xor dx,dx
   ; mov ax,[size]
   ; mov cx,0x0200
   ; mul cx
   ; xor ecx,ecx
   ; mov cx,ax
   ; ;mov ecx,0x00000800
   ; mov [EnableDigitized],1                       ;Tells the irq0 handler to process the routines
; Play_Repeat:
   ; lodsb                                              ;Loads a byte from ESI to AL
   ; hlt                                                 ;Wait for IRQ to fire
   ; loop Play_Repeat                              ;and the whole procedure is looped ECX times
   ; mov [EnableDigitized],0                     ;Tells the irq0 handler to disable the digitized functions
   ; mov cx,0x12                                 
   ; call ProgramPIT                                       ;Return to 18.2 kHz IRQ0
   ; call Sound_Off                                        ;Turn the speaker off just in case
   ; ret

; set_timer:
; mov al,0xb6
; out 0x43,al
; mov ax,1193
; out 0x43,al
; shr ax,8
; out 0x43,al
; ret

; ProgramPIT:
; ;mov al,0x36
; mov al,0xb6
; out 0x43,al
; ;mov ax,1193
; mov eax,1193180
; mov ebx,[loc]
; div ebx ;frequency
; out 0x43,al
; shr ax,8
; out 0x43,al
; ret

;int09h:
;xor dx,dx
;mov ds,dx
;mov es,dx

;in al,0x60
;call printf

;mov al,0x09
;call ackport
;call clrport64
;iret

int1ch:
pusha
mov bp,ds
push bp
mov bp,es
push bp
xor bp,bp
mov ds,bp
mov es,bp

cmp byte [multi],0xf0
;jmp .multitasking_off
jne .multitasking_off
call pcbsave
inc byte [currentprocess]
push ax
mov ax,[totalprocess]
cmp [currentprocess],ax
jg .pmore
jmp .jump
.pmore:
mov byte [currentprocess],0
.jump:
pop bp
pop bp
pop ax
pop ax
pop ax
call pcbload
;mov ax,[bp]
;call printwordh
jmp word [bp]

.multitasking_off:
;xor bp,bp
;mov es,bp
;mov bp,0x0046
;inc dword [es:bp]
;mov al,'*'
;call printf
;call chkkey
;cmp ah,0x0F
;je .pagekey
;cmp ah,0x44
;je .quitkey
;je .pagekey
;jmp .done
;.pagekey:
;call directgetkey
;call page_change_c
;jmp .done
;.quitkey:
;call directgetkey
;cli
;pop ax
;pop ax
;xor ax,ax
;push ax
;mov ax,kernel
;push ax
;sti
;.done:
;call getpos
mov al,0x1c
call ackport
pop dx
mov es,dx
pop dx
mov ds,dx
popa
iret

int60h:
pusha
xor ax,ax
mov ds,ax
mov es,ax
popa
call debug_int

mov al,0x60
call ackport
iret

int61h:
pusha
xor ax,ax
mov ds,ax
mov es,ax
mov al,0x61
call ackport
popa

cmp ah,0x00
je int61h_message
cmp ah,0x01
je int61h_set_color
cmp ah,0x02
je int61h_set_color2
cmp ah,0x03
je int61h_prnstr
cmp ah,0x04
je int61h_getstr
cmp ah,0x05
je int61h_cmpstr
cmp ah,0x06
je int61h_cls
cmp ah,0x07
je int61h_set_size
cmp ah,0x08
je int61h_change_typemode
cmp ah,0x09
je int61h_delay
cmp ah,0x0A
je int61h_slow
cmp ah,0x0B
je int61h_newline
cmp ah,0x0C
je int61h_set_prompt
cmp ah,0x0D
je int61h_pipestore
cmp ah,0x0E
je int61h_mint
cmp ah,0x0F
je int61h_kernelreturn
cmp ah,0x10
je int61h_storescreen
cmp ah,0x11
je int61h_restorescreen
cmp ah,0x12
je int61h_setmessage
cmp ah,0x13
je int61h_getmessage
cmp ah,0x14
je int61h_reload_words
cmp ah,0x15
je int61h_cmpstr_s
cmp ah,0x16
je int61h_scroll_down
cmp ah,0x20
je int61_printn
cmp ah,0x21
je int61_getno
cmp ah,0x22
je int61_printh
cmp ah,0x23
je int61_gethex
cmp ah,0x24
je int61_printwordh
cmp ah,0x25
je int61_printdwordh
cmp ah,0x26
je int61_printnb
cmp ah,0x27
je int61_printn_big
cmp ah,0x28
je int61_getno_big
cmp ah,0x30
je int61_getpos
cmp ah,0x31
je int61_setpos
cmp ah,0x32
je int61_get_typemode
cmp ah,0x33
je int61_strlen
cmp ah,0x40
je int61_inputbox_str_top
cmp ah,0x41
je int61_inputbox_no
cmp ah,0x41
je int61_inputbox_no_big
cmp ah,0x43
je int61_inputbox_hex
cmp ah,0x44
je int61_inputbox_str
cmp ah,0x45
je int61_msgbox_no_byte
cmp ah,0x46
je int61_msgbox_no
cmp ah,0x47
je int61_msgbox_no_big
cmp ah,0x48
je int61_msgbox_hex
cmp ah,0x49
je int61_msgbox_wordhex
cmp ah,0x70
je int61_getcluster
cmp ah,0x71
je int61_setcluster
cmp ah,0x72
je int61_loadcluster
cmp ah,0x73
je int61_savecluster
cmp ah,0x74
je int61_LBACHS
cmp ah,0x80
je int61_roamselect
cmp ah,0x81
je int61_save_file
iret

int61h_message:
mov si,dx

call color_switch

call getpos
push dx
xor dx,dx
call setpos
call storeline
xor dx,dx
call setpos
call prnstr
call getkey
call color_switch
xor dx,dx
call setpos
call restoreline
pop dx
call setpos
iret

int61h_set_color:
mov [color],dl
iret

int61h_set_color2:
mov [color2],dl
iret

int61h_prnstr:
mov si,dx
call prnstr
iret

int61h_getstr:
mov di,dx
call getstr
iret

int61h_cmpstr:
xor al,al
mov si,bx
mov di,dx
call cmpstr
jc .sequal
mov al,0x0F
jmp .done
.sequal:
mov al,0xF0
.done:
iret

int61h_cls:
call clear_screen
xor dx,dx
dec dh
call setpos
iret

int61h_set_size:
mov [size],dl
iret

int61h_change_typemode:
not byte [teletype]
iret

int61h_delay:
call delay
iret

int61h_slow:
call delay
iret

int61h_newline:
call newline
iret

int61h_set_prompt:
mov si,dx
mov di,prompt
mov cx,0x000F
call memcpy
clc
iret

int61h_pipestore:
mov di,dx
mov si,di
call pipespace2enter
mov si,di
call pipestore
iret

int61h_mint:
mov al,dl
mov di,found
stosb
xor al,al
stosb
call command
iret

int61h_kernelreturn:
mov byte [kernelreturnflag],0xf0
mov word [kernelreturnaddr],int61h_kernelreturn_ret
jmp command_start
int61h_kernelreturn_ret:
iret

int61h_storescreen:
call getpos
push dx
call storescreen
pop dx
call setpos
iret

int61h_restorescreen:
call getpos
push dx
call restorescreen
pop dx
call setpos
iret

int61h_setmessage:
mov [message],dx
iret

int61h_getmessage:
mov dx,[message]
iret

int61h_reload_words:
mov bx,dx
call reload_words
iret

int61h_cmpstr_s:
xor al,al
mov si,bx
mov di,dx
call cmpstr_s
jc .sequal
mov al,0x0F
jmp .done
.sequal:
mov al,0xF0
.done:
iret

int61h_scroll_down:
call scroll_down
iret

int61_printn:
mov ax,dx
call printn
iret

int61_getno:
call getno
mov dx,ax
iret

int61_printh:
mov al,dl
call printh
iret

int61_gethex:
call gethex
mov dl,al
iret

int61_printwordh:
mov ax,dx
call printwordh
iret

int61_printdwordh:
xchg ax,dx
mov dx,bx
call printdwordh
iret

int61_printnb:
mov al,dl
call printnb
iret

int61_printn_big:
mov eax,edx
call printn_big
iret

int61_getno_big:
call getno_big
mov edx,eax
iret

int61_getpos:
call getpos
iret

int61_setpos:
call setpos
iret

int61_get_typemode:
mov dl,[teletype]
iret

int61_strlen:
mov si,dx
call strlen
mov dx,cx
iret

int61_inputbox_str_top:
mov si,dx
mov di,bx
call color_switch

call getpos
push dx
push di
xor dx,dx
call setpos
call storeline
xor dx,dx
call setpos
call prnstr
call colon
pop di
call getstr
call color_switch
xor dx,dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_inputbox_no:
mov si,bx
push cx

call color_switch

call getpos
;push dx
;pop bx
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
call getno
mov di,ax
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
mov dx,di
iret

int61_inputbox_no_big:
mov si,bx
push cx

call color_switch

call getpos
;push dx
;pop bx
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
call getno_big
mov edi,eax
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
mov edx,edi
iret

int61_inputbox_hex:
mov si,bx
push cx

call color_switch

call getpos
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
call gethex
xor ah,ah
mov di,ax
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
mov dx,di
iret

int61_inputbox_str:
mov si,bx
mov di,dx
push cx

call color_switch

call getpos
;push dx
;pop bx
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
call getstr
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_msgbox_no_byte:
mov si,bx
mov di,dx
push cx

call color_switch

call getpos
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
mov ax,di
call printnb
call getkey
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_msgbox_no:
mov si,bx
mov di,dx
push cx

call color_switch

call getpos
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
mov ax,di
call printn
call getkey
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_msgbox_no_big:
mov si,bx
mov edi,edx
push cx

call color_switch

call getpos
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
mov eax,edi
call printn_big
call getkey
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_msgbox_hex:
mov si,bx
mov di,dx
push cx

call color_switch

call getpos
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
mov ax,di
call printh
call getkey
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_msgbox_wordhex:
mov si,bx
mov di,dx
;push dx
push cx

call color_switch

call getpos
mov bx,dx
pop dx
push bx
push dx
call setpos
call storeline
pop dx
push dx
call setpos
call prnstr
mov ax,di
call printwordh
call getkey
call color_switch
pop dx
call setpos
call restoreline
pop dx
call setpos
iret

int61_getcluster:
mov dx,[cluster]
iret
int61_setcluster:
mov [cluster],dx
iret
int61_loadcluster:
mov ax,dx
call LBACHS
mov bx,[locf4]
call fileload_c
mov ax,[locf4]
iret
int61_savecluster:
mov ax,[cluster]
call LBACHS
mov bx,[locf4]
call filesave_c
iret
int61_LBACHS:
mov ax,[cluster]
call LBACHS
mov al,[size]
mov ch, BYTE [absoluteTrack]
mov cl, BYTE [absoluteSector]
mov dh, BYTE [absoluteHead]
mov byte dl,[drive]
iret

int61_roamselect:
mov di,dx
mov bx,[currentdir]
mov [var_c],bx
mov word [comm],0x0f0f
mov byte [found],'t'
mov bx,roam_ret
mov [extra],bx
jmp fdir
roam_ret:
mov bx,[var_c]
mov [currentdir],bx
iret

int61_save_file:
mov bx,dx
call filesave_c
clc
iret

int62h:
pusha
xor ax,ax
mov ds,ax
mov es,ax
mov al,0x62
call ackport
popa
jmp int62_card
iret
int62_card:
pusha
mov al,218
call printf
mov al,196
call printf
mov al,191
call printf
call getpos
sub dl,3
inc dh
call setpos
mov al,179
call printf
call space
mov al,179
call printf
call getpos
sub dl,3
inc dh
call setpos
mov al,179
call printf
call space
mov al,179
call printf
call getpos
sub dl,3
inc dh
call setpos
mov al,192
call printf
mov al,196
call printf
mov al,217
call printf

call getpos
dec dh
sub dl,2
call setpos
popa
pusha
cmp dh,'H'
je .heart
cmp dh,'D'
je .diamond
cmp dh,'C'
je .club
cmp dh,'S'
je .spade
cmp dh,'h'
je .heart
cmp dh,'d'
je .diamond
cmp dh,'c'
je .club
cmp dh,'s'
je .spade
cmp dh,1
je .heart
cmp dh,2
je .diamond
cmp dh,3
je .club
jmp .spade
.coatdrawn:
call printf
call getpos
dec dh
dec dl
call setpos
popa
cmp dl,0
je .ace
cmp dl,11
je .jack
cmp dl,12
je .queen
cmp dl,13
je .king
cmp dl,14
je .ace
mov al,dl
call printn
.armyshown:
call getpos
dec dh
sub dl,2
call setpos
iret
.heart:
mov al,0x03
jmp .coatdrawn
.diamond:
mov al,0x04
jmp .coatdrawn
.club:
mov al,0x05
jmp .coatdrawn
.spade:
mov al,0x06
jmp .coatdrawn
.ace:
mov al,'A'
call printf
jmp .armyshown
.jack:
mov al,'J'
call printf
jmp .armyshown
.queen:
mov al,'Q'
call printf
jmp .armyshown
.king:
mov al,'K'
call printf
jmp .armyshown

int64h:
pusha
xor ax,ax
mov ds,ax
mov es,ax
mov al,0x62
call ackport
popa

cmp ah,0x01
je int64_getsize
cmp ah,0x02
je int64_getcolor
cmp ah,0x03
je int64_getcolor2
cmp ah,0x04
je int64_getscrolllen
cmp ah,0x05
je int64_getpage
iret

int64_getsize:
mov dl,[size]
iret

int64_getcolor:
mov dl,[color]
iret

int64_getcolor2:
mov dl,[color2]
iret

int64_getscrolllen:
mov dl,[scrolllength]
iret

int64_getpage:
mov dx,[page]
xchg dh,dl
iret

newprompt:
call getpos
xor dl,dl
call setpos
mov si,prompt
call prnstr
ret

alarm:
mov al,'H'
call printf
call colon
call gethex
mov ch,al
push cx
call colon
mov al,'M'
call printf
call colon
call gethex
pop cx
mov cl,al
push cx
call colon
mov al,'S'
call printf
call colon
call gethex
pop cx
mov dh,al
pusha
cmp byte [autostart],0xf0
jne .autostart_off
mov ah,0x08
int 0x1a
.autostart_off:
popa
mov ah,0x06
int 0x1a
jmp kernel

alarmtext:
mov di,alarmtextstr
call getstr
jmp kernel

c_setting_f:
mov si,c_size
call prnstr
call colon
mov al,[size]
call printnb
call space
mov si,c_head
call prnstr
call colon
mov al,[head]
call printnb
call space
mov si,c_track
call prnstr
call colon
mov al,[track]
call printnb

call newline
mov al,'H'
call printf
call colon
mov al,[absoluteHead]
call printh
call space
mov al,'T'
call printf
call colon
mov al,[absoluteTrack]
call printh
call space
mov al,'S'
call printf
call colon
mov al,[absoluteSector]
call printh

call newline
mov si,c_color
call prnstr
call colon
mov al,[color]
call printnb

call space
mov si,c_color2
call prnstr
call colon
mov al,[color2]
call printnb

call newline
mov si,c_drive
call prnstr
call colon
mov al,[drive]
call printnb
call space
mov si,c_drive2
call prnstr
call colon
mov al,[drive2]
call printnb

call newline
mov si,c_videomode
call prnstr
call colon
mov al,[mode]
call printnb

call newline
mov si,c_difficulty
call prnstr
call colon
mov al,[difficulty]
call printnb

call space
mov si,c_length
call prnstr
call colon
mov al,[length]
call printnb

call newline
mov si,c_scrolllen
call prnstr
call colon
mov al,[scrolllength]
call printnb

call newline
mov si,c_frame
call prnstr
call colon
mov al,[frame]
call printnb

call newline
mov si,process_returnstr
call prnstr
call colon
mov al,[returncode]
call printh

call newline
mov si,filestr
call prnstr
call colon
call space
mov si,c_loc
call prnstr
mov al,'0'
call printf
call colon
mov ax,[loc]
call printwordh

call space
mov si,c_loc
call prnstr
mov al,'1'
call printf
call colon
mov ax,[locf1]
call printwordh

call space
mov si,c_loc
call prnstr
mov al,'2'
call printf
call colon
mov ax,[locf2]
call printwordh

call space
mov si,c_loc
call prnstr
mov al,'3'
call printf
call colon
mov ax,[locf3]
call printwordh

call newline
mov si,filestr
call prnstr
call colon
call space
mov si,c_loc
call prnstr
mov al,'4'
call printf
call colon
mov ax,[locf4]
call printwordh

call space
mov si,c_loc
call prnstr
mov al,'5'
call printf
call colon
mov ax,[locf5]
call printwordh

call space
mov si,c_loc
call prnstr
mov al,'6'
call printf
call colon
mov ax,[locf6]
call printwordh

call space
mov si,c_loc
call prnstr
mov al,'7'
call printf
call colon
mov ax,[locf7]
call printwordh

call newline
mov si,c_loc2
call prnstr
call colon
mov ax,[loc2]
call printwordh

call space
mov si,c_loc3
call prnstr
call colon
mov ax,[loc3]
call printwordh

call newline
mov si,c_setdir
call prnstr
call colon
mov ax,[currentdir]
call printwordh

call newline
mov si,c_page
call prnstr
call colon
mov ax,[page]
call printwordh

call space
mov si,messagestr
call prnstr
call colon
mov ax,[message]
call printwordh

call newline
mov si,c_fname
call prnstr
call colon
mov si,ImageName
call prnstr

call newline
mov si,c_prompt
call prnstr
call colon
mov si,prompt
call prnstr

call newline
mov si,c_alarmtext
call prnstr
call colon
mov si,alarmtextstr
call prnstr

call newline
mov si,c_typemode
call prnstr
call colon
mov si,teletype
call switchshow

call space
mov si,c_scrollmode
call prnstr
call colon
mov si,scrollmode
call switchshow

call newline
mov si,c_slowmode
call prnstr
call colon
mov si,slowmode
call switchshow

call space
mov si,c_score
call prnstr
call colon
mov si,score
call switchshow

call newline
mov si,c_rollcolor
call prnstr
call colon
mov si,rollcolor
call switchshow

call newline
mov si,c_autostart
call prnstr
call colon
mov si,autostart
call switchshow

call space
mov si,c_cursor
call prnstr
call colon
mov si,cursor
call switchshow

call newline
mov si,c_micro
call prnstr
call colon
mov si,micro
call switchshow

call space
mov si,c_multi
call prnstr
call colon
mov si,multi
call switchshow

jmp kernel

switchshow:
lodsb
cmp al,0xf0
je .switchon
cmp al,0x0f
je .switchoff
dec si
mov al,0x0f
mov [si],al
.switchoff:
mov si,coff
call prnstr
ret
.switchon:
mov si,con
call prnstr
ret

pipe:
mov di,found
call getstr
mov si,found
call pipespace2enter
mov si,found
call pipestore
jmp kernel

pipespace2enter:
lodsb
cmp al,0x20
je .space
cmp al,0x00
je .end
jmp pipespace2enter
.space:
mov al,0x0D
dec si
mov [si],al
jmp pipespace2enter
.end:
ret

pipestore:
lodsb
cmp al,0x0D
je .enter
cmp al,0x00
je .end
mov ah,0x00
call keybsto
jmp pipestore
.enter:
mov ah,0x1C
call keybsto
jmp pipestore
.end:
ret

keybsto:
mov ch,ah
mov cl,al
mov ah,0x05
int 16h
ret

pcbsave:
pusha
mov al,[currentprocess]
xor ah,ah
mov bx,23
mul bx
mov bx,ax
add bx,3
mov si,pcb
add si,bx

pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2
pop ax
mov [si],ax
add si,2

pushf
pop ax
mov [si],ax
add si,2

pop bx
pop ax
push bx
mov [si],ax

ret

pcbload:
mov al,[currentprocess]
xor ah,ah
mov bx,23
mul bx
mov bx,ax
add bx,3
mov bp,pcb
add bp,bx

mov ax,[bp]
add bp,2
mov di,ax

mov ax,[bp]
add bp,2
mov si,ax

;mov ax,[bp]
add bp,2

mov ax,[bp]
add bp,2
mov sp,ax

mov ax,[bp]
add bp,2
mov bx,ax

mov ax,[bp]
add bp,2
mov dx,ax

mov ax,[bp]
add bp,2
mov cx,ax

mov ax,[bp]
add bp,2

add bp,2
ret

read:
mov al,[teletype]
mov [col],al
mov byte [teletype],0xf0
call newline
call newline
call getpos
dec dh
call setpos
xor dx,dx
mov [var_a],dx
xor ax,ax
mov al,[size]
mov bx,0x200
mul bx
;cmp dx,0
;jg .small_file
;mov ax,0xFFFF
;.small_file:
mov [var_b],ax
.read_loop:
mov si,[loc]
add si,[var_a]
.loop:
lodsb
cmp al,0x09
je .tab
call printf
inc word [var_a]
mov dx,[var_a]
cmp dx,[var_b]
jge .filedone
call getpos
cmp dh,24
jge .bottom
jmp .loop
.bottom:
call getpos
push dx
xor dl,dl
call setpos
call space
mov si,c_loc
call prnstr
call colon
;call newline
mov ax,[var_a]
call printwordh
mov al,'/'
call printf
mov ax,[var_b]
call printwordh
call space
call space
mov ax,[var_a]
xor dx,dx
mov bx,100
mul bx
mov bx,[var_b]
div bx
call printn
mov al,'%'
call printf
call space
call space
pop dx
.control:
call getkey
cmp ah,0x01
je .filedone
cmp ah,0x29
je .filedone
cmp ah,0x1C
je .pagedown
cmp ah,0x51
je .pagedown
cmp ah,0x47
je .pageup
cmp ah,0x49
je .pageup
cmp ah,0x3C
je .jump
cmp ah,0x3D
je .jump
cmp ah,0x3B
je .help
push dx
call getpos
xor dl,dl
call setpos
call clearline
call scroll_down
pop dx
mov dh,0x17
sub dh,[scrolllength]
call setpos
jmp .read_loop
.filedone:
mov al,[col]
cmp al,0xf0
je .filedoneskip
mov byte [teletype],0x0f
.filedoneskip:
jmp kernel
.help:
mov dx,read_helpstr
xor ah,ah
int 61h
jmp .control
.jump:
mov si,c_jmp
call prnstr
call space
call colon
call gethex
mov bx,var_a
inc bx
mov [bx],al
call gethex
dec bx
mov [bx],al
jmp .pagedown
.pageup:
mov dx,[var_a]
sub dx,0x07D0
mov [var_a],dx
.pagedown:
call clear_screen
xor dx,dx
call setpos
jmp .read_loop
.tab:
mov cl,[length]
xor ch,ch
mov al,0x20
.tabloop:
call printf
dec cx
cmp cx,0
jg .tabloop
jmp .loop

c_cursor_f:
not byte [cursor]
cmp byte [cursor],0xf0
je .on
mov ch,0x20
mov ah,0x01
int 0x10
jmp kernel
.on:
mov cx,0x0506
mov ah,0x01
int 0x10
jmp kernel

c_difficulty_f:
mov si,difficulty
call change
jmp kernel

signature:
db 'DivJ',0
jmp kernel

calc_options:
db '1.Add 2.Sub 3.Mul 4.Div 5.dtoh',0
drive_type_string:
db 'DriveType:',0
drive_number_string:
db 'Number of Drives:',0
drive_spt_string:
db 'Sectors per Track:',0
drive_head_string:
db 'Number of Heads:',0

EnableDigitized     db 0

bpbBytesPerSector:  	DW 512
bpbSectorsPerCluster: 	DB 1
bpbReservedSectors: 	DW 1
bpbNumberOfFATs: 	DB 2
bpbRootEntries: 	DW 224
bpbTotalSectors: 	DW 2880
bpbMedia: 		DB 0xf0  ;; 0xF1
bpbSectorsPerFAT: 	DW 9
bpbSectorsPerTrack: 	DW 18
bpbHeadsPerCylinder: 	DW 2
bpbHiddenSectors: 	DD 0
bpbTotalSectorsBig:     DD 0

datasector  dw 0x0000
cluster     dw 0x0000
absoluteSector db 0x05
absoluteHead   db 0x00
absoluteTrack  db 0x00

difficulty:
db 0x00
scrolllength:
db 0x01
length:
db 0x06
ball_x:
dw 0x000C
ball_y:
dw 0x000C
down_flag:
db 0xF0
right_flag:
db 0xF0
AI_flag:
db 0xF0
play_chance_flag:
dw 0x00F0
player_x:
dw 0x000A
player_y:
dw 0x000C
player2_x:
dw 0x0000
player2_y:
dw 0x0000

message:
dw 0

LBUTTON db 0x00 
RBUTTON db 0x00 
MBUTTON db 0x00 
XCOORD	db 0x00 
YCOORD	db 0x00 
XCOORDN db 0x00 
YCOORDN db 0x00 
XFLOW	db 0x00 
YFLOW	db 0x00 

var_p:
dw 0,0

var_a:
dw 0x0000
var_b:
dw 0x0000
var_c:
dw 0x0000
var_d:
dw 0x0000

var_x	db 0x00

strlbt	db "Left btn:   ", 0x00
strrbt	db "Rigt btn:  ", 0x00
strmbt	db "Midl btn: ", 0x00
strcdx	db "X:", 0x00
strcdy	db "Y:", 0x00
strneg	db "-", 0x00
row	db 0x00
col	db 0x00

head:
db 0x00
track:
db 0x00

DRIVE_TYPE:
db 0x00
SECTORS_PER_TRACK:
dw 0x0000
NUMBER_OF_DRIVES:
dw 0x0000
NUMBER_OF_HEADS:
dw 0x0000

teletype:
db 0x0f
rollcolor:
db 0x0f
scrollmode:
db 0xf0
slowmode:
db 0x0f
score:
db 0xf0
autostart:
db 0x0f
micro:
db 0xf0
multi:
db 0x0f
cursor:
db 0xf0
currentdir:
dw 0x1300
returncode:
db 0x00
size:
db 0x01
drive:
db 0x80
drive2:
db 0x80
mode:
db 0x03
color:
db 0x31
color2:
db 0x74
frame:
db 0x0A
xmouse:
dw 0x0000
ymouse:
dw 0x0000
page:
dw 0x0000
loc:
dw 0x6000
locf1:
dw 0x6500
locf2:
dw 0x7000
locf3:
dw 0x7500
locf4:
dw 0x8000
locf5:
dw 0x8500
locf6:
dw 0x9000
locf7:
dw 0x9500
loc2:
dw 0x8000
loc3:
dw 0x9000
extra:
dw 0x0000
comm:
dw 0x0000
comm2:
dw 0x0000

kernelreturnflag:
db 0x0F
kernelreturnaddr:
dw 0

c_load:
db 'load',0
c_save:
db 'save',0
c_run:
db 'run',0
c_batch:
db 'batch',0
c_text:
db 'text',0
c_code:
db 'code',0
c_doc:
db 'doc',0
c_read:
db 'read',0
c_type:
db 'type',0
c_print:
db 'print',0
c_clock:
db 'clock',0
c_frame:
db 'frame',0
c_drive:
db 'drive',0
c_drive2:
db 'drive2',0
c_driveinfo:
db 'driveinfo',0
c_debug:
db 'debug',0
c_pipe:
db 'pipe',0
c_loc:
db 'loc',0
c_loc2:
db 'loc2',0
c_loc3:
db 'loc3',0
c_htod:
db 'htod',0
c_bhtod:
db 'bhtod',0
c_reset:
db 'reset',0
c_cls:
db 'cls',0
c_prompt:
db 'prompt',0
c_color:
db 'color',0
c_color2:
db 'color2',0
c_typemode:
db 'typemode',0
c_videomode:
db 'videomode',0
c_scrolllen:
db 'scrolllen',0
c_difficulty:
db 'difficulty',0
c_length:
db 'length',0
c_rollcolor:
db 'rollcolor',0
c_scrollmode:
db 'scrollmode',0
c_slowmode:
db 'slowmode',0
c_memsize:
db 'memsize',0
c_micro:
db 'micro',0
c_multi:
db 'multi',0
c_settime:
db 'settime',0
c_setdate:
db 'setdate',0
c_alarm:
db 'alarm',0
c_alarmtext:
db 'alarmtext',0
c_autostart:
db 'autostart',0
c_setting:
db 'setting',0
c_install:
db 'install',0
c_score:
db 'score',0
c_icon:
db 'icon',0
c_point:
db 'point',0
c_page:
db 'page',0
c_track:
db 'track',0
c_head:
db 'head',0
c_size:
db 'size',0
c_fname:
db 'fname',0
c_fnew:
db 'fnew',0
c_fsave:
db 'fsave',0
c_rename:
db 'rename',0
c_del:
db 'del',0
c_roam:
db 'roam',0
c_dir:
db 'dir',0
c_setdir:
db 'setdir',0
c_newdir:
db 'newdir',0
c_sound:
db 'sound',0
c_reboot:
db 'reboot',0
c_restart:
db 'restart',0
c_step:
db 'step',0
c_play:
db 'play',0
c_calc:
db 'calc',0
c_bcalc:
db 'bcalc',0
c_paint:
db 'paint',0
c_video:
db 'video',0
c_vedit:
db 'vedit',0
c_star:
db 'star',0
c_help:
db 'help',0
c_cursor:
db 'cursor',0
c_cli:
db 'cli',0
c_hlt:
db 'hlt',0
c_fhlt:
db 'fhlt',0
c_jmp:
db 'jmp',0
axs:
db 'AX',0
cxs:
db 'CX',0
dxs:
db 'DX',0
bxs:
db 'BX',0
sps:
db 'SP',0
bps:
db 'BP',0
sis:
db 'SI',0
dis:
db 'DI',0
ips:
db 'IP',0
flags:
db '   Flags  ',0
dss:
db 'DS',0
ess:
db 'ES',0
sss:
db 'SS',0
css:
db 'CS',0
bmps:
db 'BMP',0
txts:
db 'TXT',0
coms:
db 'COM',0
pics:
db 'PIC',0
vids:
db 'VID',0
pnts:
db 'PNT',0
shutdownstr:
db 'System Halted. Safe to turn off.',0
process_returnstr:
db 'Return Value',0
drive_f:
db 'Drive Started:',0
imsgf:
db 'Floppy disk:',0
imsgh:
db 'Hard disk:',0
imsgo:
db 'Other:',0
imsgs:
db 'Installation Successful.',0
messagestr:
db 'message',0
freespacestr:
db 'free space',0
imsge:
db 'Failed',0
successstr:
db 'Success',0

gdtinfo: dw gdt_end - gdt -1
dd gdt
gdt: dd 0,0
flatdesc: db 0xff,0xff,0,0,0,10010010b,11001111b,0
gdt_end:
db 0

verstring:
db ' Clone OS (version 7.1.6)',0
main_list:
db 'Basic cmnds : load,save,run,batch',0
editor_list:
db 'View/Editors: text,code,doc,read,type,point,icon,paint,vedit,video',0
setting_list:
db 'SettingsCmds: loc,loc2,loc3,prompt,color,color2,drive,drive2,scrolllen,frame',0
setting2_list:
db 'Setting2Cmds: length,difficulty,cursor,head,track,page,size',0
showsetting_list:
db 'Show Setting: driveinfo,debug,memsize,setting',0
setting_switch_list:
db 'SetngSwitchs: score,rollcolor,micro,videomode,scrollmode,slowmode,typemode',0
redo_list:
db 'THE Re-Doers: restart,reboot,reset,cls',0
assembly_code:
db 'OldeAssembly: cli,jmp,hlt,fhlt',0
common_control:
db 'Common Keys : Arrow,wasd,F1 series,Tab- Change,E,(Esc or ~) - Close',0
loc_command:
db 'LocationCmds: loc(files and programs),loc2(Folder),loc3(FAT)',0
experimental:
db 'Experimental: step,multi,sound,star,print',0
file_command:
db 'FATFileComms: z-FDir,x-FSave,fname,a-cmpload,n-Fnew,q-quickload',0
dir_command:
db 'DirectoryCmd: dir,setdir,newdir,fsave,fnew,del,rename,roam',0
interrupt_api:
db 'InterruptAPI: 01=step 05=prnscr 20=quit 21,61,64=api 2c=msg 4a=alarm 60=debug',0
interrupt2_api:
db ' Interrupt2 : 1c=timer 03=debug 06=invalid 07=math 1b=ctrl+brk 62=card',0
time_list:
db 'Time setting: settime,setdate,alarm,alarmtext,autostart',0
extra_list:
db 'Misc / Extra: pipe,install,htod,bhtod,help,calc,bcalc,clock,play',0
mint_list:
db 'Andthe Mints: d-date,t-time,c-clock,i-charprint,h-help,v-ver',0
mint2_list:
db 'Moreof Mints: m-mouse,s-space,p-pause,u-up,b-below,o-oh,l-line,e-exit',0
alarmtextstr:
db ' Alarm :Press {any key to jmp to kernel} or {enter to continue}.',0
play_helpstr:
db 0x1B,0x18,0x19,0x1A,'-Player1, wasd-Player2, E-clrscr,(Esc,~)-Close, F1-Help, F2,F3-Change mode',0
doc_helpstr:
db 0x1B,0x18,0x19,0x1A,'-Move,(Esc,~)-Close, F1-Help,F3-Copy,Insert-Paste,F5-Details',0
read_helpstr:
db '(Enter,PgDwn)-Read Next Page, (Home,PgUp)-GoBack, (F2,F3)-jmp to bookmark',0
vedit_helpstr:
db 0x1B,0x18,0x19,0x1A,'-Move,Esc-Close,F1-Help,F3-Copy,F4-Paste,F5-Details',0
vedit_helpstr2:
db '    Del-ColorDown,End-ColorUp,    Insert-CharDown,Home-CharUp',0
vedit_helpstr3:
db '    PgUp-FrameUp,PgDown-FrameDown, F6-Fill,F7-Clear,F8-Clean',0
con:
db 'ON',0
coff:
db 'OFF',0
imagestr:
db 'image',0
labelstr:
db 'label',0
filestr:
db 'file',0
attribstr:
db 'attrib',0
normalstr:
db 'normal',0
readonlystr:
db 'readonly',0
hiddenstr:
db 'hidden',0
systemstr:
db 'system',0
archivestr:
db 'archive,new',0
invalidstr:
db 'Invalid',0
nomathprocstr:
db 'NoMathPrcsr',0
autorunstr:
db 'pwd confg lvlh ',0
;db 'confg pwd lvlh ',0
;db 'auto ',0
tempstr:
times 160 db 0
ImageName:
db 'COMMON  TXT'
dw 0
ImageNameTemp:
db 'COMMON  TXT'
dw 0
prompt:
db 'Bigger Picture:',0

currentprocess:
db 0
totalprocess:
db 1
pcb:
db 0x00
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x01
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x02
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x03
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x04
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x05
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x06
db 0x00
db 0x01
times 9 dw 0
dw 0

db 0x07
db 0x00
db 0x01
times 9 dw 0
dw 0

found:
db 0

times (512*38)-($-$$) db 0x90